1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using UnityEngine;
- using System.Collections;
- [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 *= AspectRatioFixer.ScaleChange;
- 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);
- UITexture[] textures = GetComponentsInChildren<UITexture>();
-
- AVDebug.Assert(textures != null && textures.Length > 0, "There must be UITextures in ScenerProp "+name);
- _minX = float.MaxValue;
- _maxX = float.MinValue;
- foreach (UITexture t in textures)
- {
- var tex= t.mainTexture;
- t.material = MenuManager._instance.mat;
-
- t.shader = Shader.Find("Unlit/Transparent Colored");
- t.mainTexture = 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();
- }
- }
|