blob: 8eecb0972a8ba1fb26ffee2c3edae02265707eab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
using System;
using System.Collections.Generic;
using UnityEngine;
public class SkinsTab : MonoBehaviour
{
public ColorChip ColorTabPrefab;
public SpriteRenderer DemoImage;
public SpriteRenderer HatImage;
public SpriteRenderer SkinImage;
public SpriteRenderer PetImage;
public FloatRange XRange = new FloatRange(1.5f, 3f);
public float YStart = 0.8f;
public float YOffset = 0.8f;
public int NumPerRow = 4;
public Scroller scroller;
private List<ColorChip> ColorChips = new List<ColorChip>();
public void OnEnable()
{
PlayerControl.SetPlayerMaterialColors((int)PlayerControl.LocalPlayer.Data.ColorId, this.DemoImage);
PlayerControl.SetHatImage(SaveManager.LastHat, this.HatImage);
PlayerControl.SetSkinImage(SaveManager.LastSkin, this.SkinImage);
PlayerControl.SetPetImage(SaveManager.LastPet, (int)PlayerControl.LocalPlayer.Data.ColorId, this.PetImage);
SkinData[] unlockedSkins = DestroyableSingleton<HatManager>.Instance.GetUnlockedSkins();
for (int i = 0; i < unlockedSkins.Length; i++)
{
SkinData skin = unlockedSkins[i];
float x = this.XRange.Lerp((float)(i % this.NumPerRow) / ((float)this.NumPerRow - 1f));
float y = this.YStart - (float)(i / this.NumPerRow) * this.YOffset;
ColorChip colorChip = UnityEngine.Object.Instantiate<ColorChip>(this.ColorTabPrefab, this.scroller.Inner);
colorChip.transform.localPosition = new Vector3(x, y, -1f);
colorChip.Button.OnClick.AddListener(delegate()
{
this.SelectHat(skin);
});
colorChip.Inner.sprite = skin.IdleFrame;
this.ColorChips.Add(colorChip);
}
this.scroller.YBounds.max = -(this.YStart - (float)(unlockedSkins.Length / this.NumPerRow) * this.YOffset) - 3f;
}
public void OnDisable()
{
for (int i = 0; i < this.ColorChips.Count; i++)
{
UnityEngine.Object.Destroy(this.ColorChips[i].gameObject);
}
this.ColorChips.Clear();
}
public void Update()
{
PlayerControl.SetPlayerMaterialColors((int)PlayerControl.LocalPlayer.Data.ColorId, this.DemoImage);
SkinData skinById = DestroyableSingleton<HatManager>.Instance.GetSkinById(SaveManager.LastSkin);
for (int i = 0; i < this.ColorChips.Count; i++)
{
ColorChip colorChip = this.ColorChips[i];
colorChip.InUseForeground.SetActive(skinById.IdleFrame == colorChip.Inner.sprite);
}
}
private void SelectHat(SkinData skin)
{
uint idFromSkin = DestroyableSingleton<HatManager>.Instance.GetIdFromSkin(skin);
SaveManager.LastSkin = idFromSkin;
PlayerControl.SetSkinImage(SaveManager.LastSkin, this.SkinImage);
if (PlayerControl.LocalPlayer)
{
PlayerControl.LocalPlayer.RpcSetSkin(idFromSkin);
}
}
}
|