-
Notifications
You must be signed in to change notification settings - Fork 96
/
CatManager.cs
115 lines (94 loc) · 4.02 KB
/
CatManager.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using UnityEngine;
namespace ModuleManager.Cats
{
public static class CatManager
{
private static Sprite[] catFrames;
private static Texture2D rainbow;
private static int scale = 1;
public static void LaunchCat()
{
InitCats();
GameObject cat = LaunchCat(scale);
CatMover catMover = cat.AddComponent<CatMover>();
}
public static void LaunchCats()
{
InitCats();
GameObject catSun = LaunchCat(scale);
CatOrbiter catSunOrbiter = catSun.AddComponent<CatOrbiter>();
catSunOrbiter.Init(null, 0);
int cats = UnityEngine.Random.Range(6, 10);
for (int i = 0; i < cats; i++)
{
GameObject cat = LaunchCat(scale);
CatOrbiter catOrbiter = cat.AddComponent<CatOrbiter>();
catOrbiter.Init(catSunOrbiter, Screen.height * 0.5f);
int moons = UnityEngine.Random.Range(0, 4);
for (int j = 0; j < moons; j++)
{
GameObject catMoon = LaunchCat(scale);
CatOrbiter catMoonOrbiter = catMoon.AddComponent<CatOrbiter>();
catMoonOrbiter.Init(catOrbiter, Screen.height * 0.06f);
}
}
}
private static void InitCats()
{
Texture2D[] tex = new Texture2D[12];
for (int i = 0; i < tex.Length; i++)
{
tex[i] = new Texture2D(70, 42, TextureFormat.ARGB32, false);
}
tex[0].LoadImage(Properties.Resources.cat1);
tex[1].LoadImage(Properties.Resources.cat2);
tex[2].LoadImage(Properties.Resources.cat3);
tex[3].LoadImage(Properties.Resources.cat4);
tex[4].LoadImage(Properties.Resources.cat5);
tex[5].LoadImage(Properties.Resources.cat6);
tex[6].LoadImage(Properties.Resources.cat7);
tex[7].LoadImage(Properties.Resources.cat8);
tex[8].LoadImage(Properties.Resources.cat9);
tex[9].LoadImage(Properties.Resources.cat10);
tex[10].LoadImage(Properties.Resources.cat11);
tex[11].LoadImage(Properties.Resources.cat12);
rainbow = new Texture2D(39, 36, TextureFormat.ARGB32, false);
rainbow.LoadImage(Properties.Resources.rainbow);
rainbow.Apply();
catFrames = new Sprite[12];
for (int i = 0; i < tex.Length; i++)
{
tex[i].Apply();
catFrames[i] = Sprite.Create(tex[i], new Rect(0, 0, tex[i].width, tex[i].height), new Vector2(.5f, .5f));
catFrames[i].name = "cat" + i;
}
scale = 1;
if (Screen.height >= 1080)
scale *= 2;
if (Screen.height > 1440)
scale *= 3;
Physics2D.gravity = Vector2.zero;
}
private static GameObject LaunchCat(int scale)
{
GameObject cat = new GameObject("NyanCat");
SpriteRenderer sr = cat.AddComponent<SpriteRenderer>();
TrailRenderer trail = cat.AddComponent<TrailRenderer>();
CatAnimator catAnimator = cat.AddComponent<CatAnimator>();
sr.sprite = catFrames[0];
trail.material = new Material(Shader.Find("Particles/Alpha Blended"));
Debug.Log("material = " + trail.material);
trail.material.mainTexture = rainbow;
trail.time = 1.5f;
trail.startWidth = 0.6f * scale * rainbow.height;
trail.endColor = Color.white.A(0.1f);
trail.colorGradient = new Gradient {alphaKeys = new GradientAlphaKey[3] { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 0.75f), new GradientAlphaKey(0.2f, 1) }};
trail.Clear();
cat.layer = LayerMask.NameToLayer("UI");
catAnimator.frames = catFrames;
cat.transform.localScale = 70 * scale * Vector3.one;
return cat;
}
}
}