1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using CommonLang;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- using CSpriteMeta = CommonUI.Cell.Game.CSpriteMeta;
- using CSpriteController = CommonUI.Cell.Game.CSpriteController;
- using CSpriteEventHandler = CommonUI.Cell.Game.CSpriteEventHandler;
- using CommonUI_Unity3D.Impl;
- using UnityEngine.UI;
- namespace CommonUnity3D.UGUI
- {
- public class CPJSprite : DisplayNode
- {
- private readonly CPJSpriteGraphics mGraphics;
- private CSpriteController mSprite;
- private CommonUI.Cell.Game.CCD mVisibleBounds;
- public CPJSprite(string name) : base(name)
- {
- this.Enable = false;
- this.EnableChildren = false;
- this.mGraphics = mGameObject.AddComponent<CPJSpriteGraphics>();
- }
- public CPJSprite(CSpriteMeta meta) : this(meta.Data.Name)
- {
- this.SpriteMeta = meta;
- }
- protected override void OnDispose()
- {
- if (mSprite != null) mSprite.Dispose();
- base.OnDispose();
- }
- public void SetPreferredBounds()
- {
- if (mSprite != null)
- {
- this.Size2D = new Vector2(mVisibleBounds.Width, mVisibleBounds.Height);
- Vector2 pivot = new Vector2(
- CMath.getRate(0, mVisibleBounds.X1, mVisibleBounds.X2),
- 1f - CMath.getRate(0, mVisibleBounds.Y1, mVisibleBounds.Y2));
- this.mTransform.pivot = pivot;
- }
- }
- public CSpriteMeta SpriteMeta
- {
- get { return mSprite.Meta; }
- set
- {
- if (mSprite != null) mSprite.Dispose();
- this.mSprite = new CSpriteController(value);
- this.mGraphics.SetSpriteMeta(this);
- this.mVisibleBounds = mSprite.Meta.getVisibleBounds();
- }
- }
- public CPJSpriteGraphics Graphics
- {
- get { return mGraphics; }
- }
- public CSpriteController Controller
- {
- get { return mSprite; }
- }
- public CommonUI.Cell.Game.CCD VisibleBounds
- {
- get { return mVisibleBounds; }
- }
- protected override void OnUpdate()
- {
- base.OnUpdate();
- if (this.mSprite != null)
- {
- this.mGraphics.SetFrame(mSprite.CurrentAnimate, mSprite.CurrentFrame);
- this.mSprite.Update();
- }
- }
- }
- }
|