123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- [RequireComponent(typeof(PoolObject))]
- public class SceneryProp : MonoBehaviour
- {
- public float minXScale = 1;
- public float maxXScale = 1;
- public float minYScale = 1;
- public float maxYScale = 1;
- public float minRotation = 0;
- public float maxRotation = 0;
- public float yOffset;
- Vector3 _originalScale;
- Vector3 _originalPosition;
- protected Transform _transform;
- private float _minX;
- private float _maxX;
- public float MinX { get { return _minX; } }
- public float MaxX { get { return _maxX; } }
- PoolObject _poolObject;
- protected virtual void Awake()
- {
- _transform = transform;
- _originalScale = _transform.localScale;
- _originalPosition = _transform.localPosition;
- _poolObject = GetComponent<PoolObject>();
- }
- protected virtual void OnSpawnMsg()
- {
- Vector3 scale = _originalScale;
- scale *= 2;
- scale.x *= Random.Range(minXScale, maxXScale);
- scale.y *= Random.Range(minYScale, maxYScale);
- _transform.localScale = scale;
- _transform.localRotation = Quaternion.Euler(0, 0, Random.Range(minRotation, maxRotation));
- _transform.localPosition = _originalPosition;
- AVDebug.Assert(_originalPosition.x == 0 && _originalPosition.y == 0, "Prefab position of Scenery is not at x/y 0,0 - " + name);
- RawImage[] textures = GetComponentsInChildren<RawImage>();
-
- AVDebug.Assert(textures != null && textures.Length > 0, "There must be UITextures in ScenerProp "+name);
- _minX = float.MaxValue;
- _maxX = float.MinValue;
- foreach (RawImage t in textures)
- {
- var tex= t.mainTexture;
- t.material = MenuManager._instance.mat;
-
- // t.shader = Shader.Find("Unlit/Transparent Colored");
- t.texture = tex;
- // Vector3[] corners = NGUIMath.CalculateWidgetCorners(t);
- //foreach (Vector3 v in corners)
- //{
- // if (v.x < _minX)
- // {
- // _minX = v.x;
- // }
- // if (v.x > _maxX)
- // {
- // _maxX = v.x;
- // }
- //}
- }
- _transform.localPosition += new Vector3(0, yOffset);
- }
- public void Despawn()
- {
- _poolObject.Despawn();
- }
- }
|