blob: 10f7b3a0c472cac09860913cf29b443e9629f0c3 (
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 HatsTab : 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);
HatBehaviour[] unlockedHats = DestroyableSingleton<HatManager>.Instance.GetUnlockedHats();
for (int i = 0; i < unlockedHats.Length; i++)
{
HatBehaviour hat = unlockedHats[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(hat);
});
colorChip.Inner.sprite = hat.MainImage;
this.ColorChips.Add(colorChip);
}
this.scroller.YBounds.max = -(this.YStart - (float)(unlockedHats.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);
HatBehaviour hatById = DestroyableSingleton<HatManager>.Instance.GetHatById(SaveManager.LastHat);
for (int i = 0; i < this.ColorChips.Count; i++)
{
ColorChip colorChip = this.ColorChips[i];
colorChip.InUseForeground.SetActive(hatById.MainImage == colorChip.Inner.sprite);
}
}
private void SelectHat(HatBehaviour hat)
{
uint idFromHat = DestroyableSingleton<HatManager>.Instance.GetIdFromHat(hat);
SaveManager.LastHat = idFromHat;
PlayerControl.SetHatImage(idFromHat, this.HatImage);
if (PlayerControl.LocalPlayer)
{
PlayerControl.LocalPlayer.RpcSetHat(idFromHat);
}
}
}
|