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
|
using System;
using System.Collections.Generic;
using UnityEngine;
public class PetsTab : 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);
PetBehaviour[] unlockedPets = DestroyableSingleton<HatManager>.Instance.GetUnlockedPets();
for (int i = 0; i < unlockedPets.Length; i++)
{
PetBehaviour pet = unlockedPets[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 chip = UnityEngine.Object.Instantiate<ColorChip>(this.ColorTabPrefab, this.scroller.Inner);
chip.transform.localPosition = new Vector3(x, y, -1f);
chip.InUseForeground.SetActive(DestroyableSingleton<HatManager>.Instance.GetIdFromPet(pet) == SaveManager.LastPet);
chip.Button.OnClick.AddListener(delegate()
{
this.SelectPet(chip, pet);
});
PlayerControl.SetPetImage(pet, (int)PlayerControl.LocalPlayer.Data.ColorId, chip.Inner);
this.ColorChips.Add(chip);
}
this.scroller.YBounds.max = -(this.YStart - (float)(unlockedPets.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();
}
private void SelectPet(ColorChip sender, PetBehaviour pet)
{
uint idFromPet = DestroyableSingleton<HatManager>.Instance.GetIdFromPet(pet);
SaveManager.LastPet = idFromPet;
PlayerControl.SetPetImage(pet, (int)PlayerControl.LocalPlayer.Data.ColorId, this.PetImage);
if (PlayerControl.LocalPlayer)
{
PlayerControl.LocalPlayer.RpcSetPet(idFromPet);
}
for (int i = 0; i < this.ColorChips.Count; i++)
{
ColorChip colorChip = this.ColorChips[i];
colorChip.InUseForeground.SetActive(colorChip == sender);
}
}
}
|