fix clouds
This commit is contained in:
parent
99d987065d
commit
3c37d450f1
File diff suppressed because it is too large
Load diff
|
@ -83,6 +83,12 @@ TextureImporter:
|
|||
- first:
|
||||
213: -1969074579828895637
|
||||
second: Fort_Left_Arm
|
||||
- first:
|
||||
213: 8759155364766697816
|
||||
second: AirRally_1_27
|
||||
- first:
|
||||
213: 4088167666801983468
|
||||
second: AirRally_1_28
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
|
@ -537,7 +543,7 @@ TextureImporter:
|
|||
width: 404
|
||||
height: 404
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -558,7 +564,7 @@ TextureImporter:
|
|||
width: 404
|
||||
height: 404
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -579,7 +585,7 @@ TextureImporter:
|
|||
width: 340
|
||||
height: 596
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -600,7 +606,7 @@ TextureImporter:
|
|||
width: 276
|
||||
height: 308
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -621,7 +627,7 @@ TextureImporter:
|
|||
width: 340
|
||||
height: 340
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -642,7 +648,7 @@ TextureImporter:
|
|||
width: 340
|
||||
height: 340
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -663,7 +669,7 @@ TextureImporter:
|
|||
width: 404
|
||||
height: 340
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -684,7 +690,7 @@ TextureImporter:
|
|||
width: 276
|
||||
height: 276
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -705,7 +711,7 @@ TextureImporter:
|
|||
width: 276
|
||||
height: 308
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -726,7 +732,7 @@ TextureImporter:
|
|||
width: 276
|
||||
height: 276
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
|
@ -738,6 +744,48 @@ TextureImporter:
|
|||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
- serializedVersion: 2
|
||||
name: AirRally_1_27
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 743
|
||||
y: 7
|
||||
width: 722
|
||||
height: 754
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
tessellationDetail: 0
|
||||
bones: []
|
||||
spriteID: 85940617565ce8970800000000000000
|
||||
internalID: 8759155364766697816
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
- serializedVersion: 2
|
||||
name: AirRally_1_28
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 3239
|
||||
y: 3751
|
||||
width: 338
|
||||
height: 338
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
outline: []
|
||||
physicsShape: []
|
||||
tessellationDetail: 0
|
||||
bones: []
|
||||
spriteID: cef38f935d61cb830800000000000000
|
||||
internalID: 4088167666801983468
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
|
|
71
Assets/Scripts/Games/AirRally/Cloud.cs
Normal file
71
Assets/Scripts/Games/AirRally/Cloud.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Games.Scripts_AirRally
|
||||
{
|
||||
public class Cloud : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Sprite[] sprites;
|
||||
[SerializeField] Vector3 spawnRange;
|
||||
[SerializeField] float baseSpeed = 1f;
|
||||
[SerializeField] float fadeDist = 10f;
|
||||
[SerializeField] float lifeTime = 6f;
|
||||
[SerializeField] float fadeInTime = 0.25f;
|
||||
|
||||
Camera cam;
|
||||
SpriteRenderer spriteRenderer;
|
||||
float time = 0f;
|
||||
|
||||
public bool isWorking = false;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
cam = GameCamera.GetCamera();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
spriteRenderer.color = new Color(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
transform.position += Vector3.forward * -baseSpeed * Time.deltaTime;
|
||||
|
||||
// get distance to camera
|
||||
float dist = Vector3.Distance(cam.transform.position, transform.position);
|
||||
if (dist <= fadeDist)
|
||||
{
|
||||
spriteRenderer.color = new Color(1, 1, 1, Mathf.Clamp01(dist / fadeDist));
|
||||
}
|
||||
else if (time < fadeInTime)
|
||||
{
|
||||
spriteRenderer.color = new Color(1, 1, 1, Mathf.Clamp01(time/fadeInTime));
|
||||
}
|
||||
|
||||
if (time > lifeTime)
|
||||
{
|
||||
isWorking = false;
|
||||
gameObject.SetActive(false);
|
||||
spriteRenderer.color = new Color(1, 1, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartCloud(Vector3 origin, bool prebake)
|
||||
{
|
||||
isWorking = true;
|
||||
time = 0f;
|
||||
gameObject.SetActive(true);
|
||||
spriteRenderer.sprite = sprites[Random.Range(0, sprites.Length)];
|
||||
transform.position = origin;
|
||||
transform.position += new Vector3(Random.Range(-spawnRange.x, spawnRange.x), Random.Range(-spawnRange.y, spawnRange.y), Random.Range(-spawnRange.z, spawnRange.z));
|
||||
if (prebake)
|
||||
{
|
||||
time = Random.Range(0, lifeTime);
|
||||
transform.position += Vector3.forward * -baseSpeed * time;
|
||||
float dist = Vector3.Distance(cam.transform.position, transform.position);
|
||||
spriteRenderer.color = new Color(1, 1, 1, Mathf.Clamp01(dist / fadeDist));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/AirRally/Cloud.cs.meta
Normal file
11
Assets/Scripts/Games/AirRally/Cloud.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 891c0b37d3276da4fa7ea5ba3332dc13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
65
Assets/Scripts/Games/AirRally/CloudsManager.cs
Normal file
65
Assets/Scripts/Games/AirRally/CloudsManager.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Games.Scripts_AirRally
|
||||
{
|
||||
public class CloudsManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Transform cloudRoot;
|
||||
[SerializeField] GameObject cloudPrefab;
|
||||
[SerializeField] int maxCloudAmt = 32;
|
||||
[SerializeField] int cloudsToPreBake = 10;
|
||||
[SerializeField] float cloudRepeatRate = 0.1f;
|
||||
|
||||
|
||||
Cloud[] pool;
|
||||
float time = 0f;
|
||||
float lastTime = 0f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
pool = new Cloud[maxCloudAmt];
|
||||
for (int i = 0; i < maxCloudAmt; i++)
|
||||
{
|
||||
GameObject cloudObj = Instantiate(cloudPrefab, cloudRoot);
|
||||
cloudObj.SetActive(false);
|
||||
pool[i] = cloudObj.GetComponent<Cloud>();
|
||||
pool[i].Init();
|
||||
}
|
||||
|
||||
for (int i = 0; i < cloudsToPreBake; i++)
|
||||
{
|
||||
Cloud cloud = GetAvailableCloud();
|
||||
if (cloud != null)
|
||||
{
|
||||
cloud.StartCloud(cloudRoot.position, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cloud GetAvailableCloud()
|
||||
{
|
||||
foreach (Cloud cloud in pool)
|
||||
{
|
||||
if (!cloud.isWorking)
|
||||
{
|
||||
return cloud;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time - lastTime > cloudRepeatRate)
|
||||
{
|
||||
lastTime = time;
|
||||
GetAvailableCloud()?.StartCloud(cloudRoot.position, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/AirRally/CloudsManager.cs.meta
Normal file
11
Assets/Scripts/Games/AirRally/CloudsManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f9a1426575a6edb4b8f43668daac9f21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -30,7 +30,7 @@ namespace HeavenStudio.Games.Scripts_AirRally
|
|||
|
||||
void Start()
|
||||
{
|
||||
|
||||
transform.position = OtherTarget.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
Loading…
Reference in a new issue