Пример #1
0
    // Use this for initialization
    void Start()
    {
        warCtrl = GameObject.FindWithTag("GameController").GetComponent <WarSceneController>();
        rwCrt   = GameObject.Find("RangedWeapons").GetComponent <RangedWeaponCreator>();

        sprite = GetComponent <exSprite>();
        anim   = GetComponent <exSpriteAnimation>();

        if (soliderType == 3 || soliderType == 4 || soliderType == 5)
        {
            timeCoolDown = 1;
        }
        else
        {
            timeCoolDown = 0.5f;
        }

        manPosMaxX    = WarSceneController.manPosMaxX;
        manPosMaxY    = WarSceneController.manPosMaxY;
        locationStepX = WarSceneController.locationStepX;
        locationStepY = WarSceneController.locationStepY;
        CheckLocationState();

        hitDistance1 = (int)(hitDistance / locationStepX);
    }
Пример #2
0
        public override void OnEnter()
        {
            // Get the target of the animation
            TargetGameObject = Fsm.GetOwnerDefaultTarget(gameObject);

            // If there is no target
            if (TargetGameObject == null && AnimationName != null)
            {
                Finish();
                return;
            }
            exanimation = TargetGameObject.GetComponent<exSpriteAnimation>();
            exsprite = TargetGameObject.GetComponent<exSprite>();
            exsprite.trimTexture = trimTexture.Value;
            exsprite.useTextureOffset = useTextureOffset.Value;
            if (color.Value != Color.white)
            {
                exsprite.color = color.Value;
            }else
            {
                exsprite.color = exsprite.color;
            }
            exsprite.enabled = true;
            exanimation.Stop();
            exanimation.Play(AnimationName.Value);
        }
Пример #3
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void OnEnable()
    {
        if (target != editSpAnim)
        {
            editSpAnim = target as exSpriteAnimation;
        }
    }
Пример #4
0
    void Awake()
    {
        velocity = 200f;
        direction = Vector3.down;

        animation = GetComponent<exSpriteAnimation>();
    }
Пример #5
0
    void CalcVictoryFlagPos()
    {
        if (state != ArmyState.Victory)
        {
            return;
        }

        int flag = 0;
        exSpriteAnimation moveAnim = GetComponent <exSpriteAnimation>();

        int frame = moveAnim.GetCurFrameIndex();

        if (animName == animNames[6])
        {
            flag = 0;
        }
        else if (animName == animNames[7])
        {
            flag = 1;
        }
        else if (animName == animNames[8])
        {
            flag = 2;
        }

        Vector3 pos = flagPos[flag * 3 + 9 + frame];

        if (!isHFlipped)
        {
            pos.x = -pos.x;
        }
        flagCtrl.localPosition = pos;
    }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        LM = (LevelManager)FindObjectOfType(typeof(LevelManager));

        Debug.Log("Starting #" + nHumans);
        myTransform = transform;
        spriteObj = GetComponent<exSprite>();
        spriteAnimation = GetComponent<exSpriteAnimation>();
        // Determine if I should be an alien.
        if (nAliens < maxAliens) {
            float pAlien = 0;
            if (nHumans >= nHandlers - maxAliens) {
                pAlien = 1;
            }
            else {
                pAlien = Random.Range(0, nHandlers);
            }
            if (pAlien <= 1 || nHumans >= nHandlers ) {
                Debug.Log("Human "+ nHumans + " Is an ALIEN!");
                isAlien = true;
                nAliens++;
                nHumans++;
            }
            else {
                Debug.Log("Human "+ nHumans + " Is a HUMAN!");
                nHumans++;
            }
        }
        //EventManager.instance.AddListener(this, "Oso_clicked");
        if (isAlien) {
            audio.pitch = 1.75f;
        }
    }
Пример #7
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void Trigger(exSpriteAnimation _spAnim, EventInfo _eventInfo)
    {
        if (_eventInfo.methodName == "")
        {
            return;
        }

        switch (_eventInfo.paramType)
        {
        case EventInfo.ParamType.NONE:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.msgOptions);
            break;

        case EventInfo.ParamType.STRING:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.stringParam, _eventInfo.msgOptions);
            break;

        case EventInfo.ParamType.FLOAT:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.floatParam, _eventInfo.msgOptions);
            break;

        case EventInfo.ParamType.INT:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.intParam, _eventInfo.msgOptions);
            break;

        case EventInfo.ParamType.BOOL:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.boolParam, _eventInfo.msgOptions);
            break;

        case EventInfo.ParamType.OBJECT:
            _spAnim.SendMessage(_eventInfo.methodName, _eventInfo.objectParam, _eventInfo.msgOptions);
            break;
        }
    }
Пример #8
0
 public void Awake()
 {
     // Get Component initialization in Start Event
     Animations             = gameObject.GetComponent <exSpriteAnimation>();
     distanceTimer          = 0;
     distanceUpdateInterval = 0.5f;
 }
Пример #9
0
    public void init()
    {
        m_animation         = GetComponent <exSpriteAnimation>();
        m_animationNameList = new List <string>();

        //Add listeners
        ApplicationFactory.instance.m_messageBus.TackleBattleStart += tackleBattleStart;
    }
Пример #10
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    override protected void OnEnable()
    {
        base.OnEnable();

        // NOTE: though we have ExecuteInEditMode, user can Add/Remove spanim in Editor
        if (spanim == null)
        {
            spanim = GetComponent <exSpriteAnimation>();
        }
    }
Пример #11
0
    public void InitArmyInfo(ArmyInfo ai)
    {
        armyInfo          = ai;
        armyInfo.armyCtrl = GetComponent <ArmyController>();

        SetArmyKingFlag();

        if (armyInfo.cityTo != -1)
        {
            if (pathfinding == null)
            {
                pathfinding = GameObject.FindWithTag("Pathfinding").GetComponent <MyPathfinding>();
            }
            SetRoute(pathfinding.GetRoute(armyInfo.pos, armyInfo.cityTo));
        }

        state    = (ArmyState)armyInfo.state;
        timeTick = armyInfo.timeTick;

        if (state == ArmyState.Garrison)
        {
            exSprite          moveSprite = GetComponent <exSprite>();
            exSpriteAnimation moveAnim   = GetComponent <exSpriteAnimation>();
            moveAnim.Stop();

            int frame = armyInfo.direction;
            if (frame == -1)
            {
                frame = 0;
            }
            moveAnim.SetFrame("ArmyGarrison", frame);

            Vector3 pos = flagPos[3 + frame];
            if (!armyInfo.isFlipped)
            {
                pos.x = -pos.x;
            }
            else
            {
                isHFlipped = true;
                moveSprite.HFlip();

                exSprite    flagSprite = flagCtrl.GetComponent <exSprite>();
                BoxCollider flagCol    = flagCtrl.GetComponent <BoxCollider>();
                flagSprite.HFlip();
                flagCol.center = new Vector3(-flagCol.center.x, flagCol.center.y, flagCol.center.z);
            }

            flagCtrl.localPosition = pos;
        }
        else
        {
            CalcDirection();
        }
    }
Пример #12
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected new void Awake()
    {
// DISABLE {
// #if UNITY_EDITOR
//         if ( EditorApplication.isPlaying == false &&
//              string.IsNullOrEmpty(textureGUID) == false &&
//              exAtlasDBBasic.Initialized() )
//         {
//             exAtlasDBBasic.ElementInfo elInfo = exAtlasDBBasic.GetElementInfoNoInit ( textureGUID );
//             string path = AssetDatabase.GetAssetPath(atlas_);
//             string guid = AssetDatabase.AssetPathToGUID(path);

//             //
//             if ( elInfo != null ) {
//                 if ( elInfo.indexInAtlas != index_ || elInfo.guidAtlas != guid ) {
//                     path = AssetDatabase.GUIDToAssetPath(elInfo.guidAtlas);
//                     SetSprite( (exAtlas)AssetDatabase.LoadAssetAtPath( path, typeof(exAtlas) ),
//                                elInfo.indexInAtlas );
//                     Build(null);
//                 }
//             }
//             else {
//                 Clear();
//                 path = AssetDatabase.GUIDToAssetPath(textureGUID);
//                 Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath( path, typeof(Texture2D) );
//                 Build(texture);
//             }
//         }
// #endif
// } DISABLE end

        base.Awake();
        spanim = GetComponent <exSpriteAnimation>();

        if (atlas_ != null ||
            (renderer.sharedMaterial && renderer.sharedMaterial.mainTexture != null))
        {
            if (meshFilter)
            {
                // create mesh ( in editor, this can duplicate mesh to prevent shared mesh for sprite)
                meshFilter_.mesh = new Mesh();
                meshFilter_.sharedMesh.hideFlags = HideFlags.DontSave;
                ForceUpdateMesh(meshFilter_.sharedMesh);

                // check if update mesh collider
                MeshCollider meshCollider = collider as MeshCollider;
                if (meshCollider && meshCollider.sharedMesh == null)
                {
                    this.UpdateColliderSize(0.2f);
                }
            }
        }
    }
Пример #13
0
    // DISABLE: the focus only occur when main window lost foucs, then come in {
    // // ------------------------------------------------------------------
    // // Desc:
    // // ------------------------------------------------------------------

    // void OnFocus () {
    //     OnSelectionChange ();
    // }
    // } DISABLE end

    // ------------------------------------------------------------------
    /// \param _obj
    /// Check if the object is valid sprite animation clip and open it in sprite animation clip editor.
    // ------------------------------------------------------------------

    public void Edit(Object _obj)
    {
        // check if repaint
        if (curEdit != _obj)
        {
            Object obj = _obj;

            if (obj is GameObject)
            {
                GameObject go = obj as GameObject;
                // get exSpriteAnimation from itself, children or root
                exSpriteAnimation spAnim = go.GetComponent <exSpriteAnimation>();
                // DISABLE {
                // if ( spAnim == null ) {
                //     spAnim = go.GetComponentInChildren<exSpriteAnimation>();
                //     if ( spAnim == null ) {
                //         spAnim = go.transform.root.GetComponentInChildren<exSpriteAnimation>();
                //     }
                // }
                // } DISABLE end
                if (spAnim)
                {
                    int idx = spAnim.animations.IndexOf(curEdit);
                    // if curEdit is exists in the selected gameObject, don't do anything
                    if (idx != -1)
                    {
                        Repaint();
                        return;
                    }

                    // if we have default animation, use it
                    if (spAnim.defaultAnimation != null)
                    {
                        obj = spAnim.defaultAnimation;
                    }
                    // else we will check if we have animations in our list and use the first one
                    else if (spAnim.animations.Count > 0)
                    {
                        obj = spAnim.animations[0];
                    }
                }
            }

            // if this is another anim clip, swtich to it.
            if (obj is exSpriteAnimClip && obj != curEdit)
            {
                curEdit = obj as exSpriteAnimClip;
                Init();
                Repaint();
                return;
            }
        }
    }
Пример #14
0
    public void SetResume()
    {
        if (anim == null)
        {
            anim = GetComponent <exSpriteAnimation>();
        }

        if (anim != null && anim.IsPaused())
        {
            anim.Resume();
        }
    }
Пример #15
0
    public void SetPause()
    {
        if (anim == null)
        {
            anim = GetComponent <exSpriteAnimation>();
        }

        if (anim != null && anim.IsPlaying())
        {
            anim.Pause();
        }
    }
Пример #16
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    override protected void OnDisable()
    {
        base.OnDisable();

        // NOTE: though we have ExecuteInEditMode, user can Add/Remove spanim in Editor
        if (spanim == null)
        {
            spanim = GetComponent <exSpriteAnimation>();
        }
        // DISABLE {
        // if ( spanim ) {
        //     spanim.Stop();
        // }
        // } DISABLE end
    }
Пример #17
0
    public void SetInfo(int index, bool isWithFire, float waitTime, MagicArcher archerCtrl)
    {
        this.index      = index;
        this.isWithFire = isWithFire;
        this.archerCtrl = archerCtrl;

        if (isWithFire)
        {
            fire = this.transform.GetChild(0);
            fire.localPosition = firePos[0];
        }

        anim = GetComponent <exSpriteAnimation>();
        Invoke("WaitForPlayAnim", waitTime);
    }
Пример #18
0
    public void SetOnFire()
    {
        if (state == State.Dead)
        {
            return;
        }

        isOnFire = true;

        string     fireName = "Soliders/Other/SoliderFire";
        GameObject go       = (GameObject)Instantiate(Resources.Load(fireName));

        go.transform.parent           = this.transform;
        go.transform.localPosition    = new Vector3(0, 0, -2);
        go.transform.localEulerAngles = Vector3.zero;
        go.transform.localScale       = Vector3.one;

        fireAnim = go.GetComponent <exSpriteAnimation>();
    }
Пример #19
0
    public void SetArmyGarrison()
    {
        state = ArmyState.Garrison;

        if (animName != "")
        {
            exSpriteAnimation moveAnim = GetComponent <exSpriteAnimation>();
            moveAnim.Stop();

            int frame = -1;

            if (animName == animNames[0] || animName == animNames[3] || animName == animNames[6])
            {
                frame = 0;
            }
            else if (animName == animNames[1] || animName == animNames[4] || animName == animNames[7])
            {
                frame = 1;
            }
            else if (animName == animNames[2] || animName == animNames[5] || animName == animNames[8])
            {
                frame = 2;
            }

            moveAnim.SetFrame("ArmyGarrison", frame);

            Vector3 pos = flagPos[3 + frame];

            if (!isHFlipped)
            {
                pos.x = -pos.x;
            }
            flagCtrl.localPosition = pos;

            animName = "";
        }
    }
Пример #20
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    int BackwardTriggerEvents(exSpriteAnimation _spAnim,
                              exSpriteAnimState _lastAnim,
                              int _index,
                              float _start,
                              float _end,
                              bool _includeStart)
    {
        int idx = _index;
        exSpriteAnimState curAnim = _spAnim.GetCurrentAnimation();

        for (int i = _index - 1; i >= 0; --i)
        {
            EventInfo ei = eventInfos[i];

            if (ei.time == _start && _includeStart == false)
            {
                idx = i;
                continue;
            }

            if (ei.time >= _end)
            {
                Trigger(_spAnim, ei);
                if (curAnim == null || _lastAnim != curAnim)
                {
                    return(-1);
                }
                idx = i;
            }
            else
            {
                break;
            }
        }
        return(idx);
    }
Пример #21
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    protected override void Awake()
    {
        // DISABLE {
        // #if UNITY_EDITOR
        //         if ( EditorApplication.isPlaying == false &&
        //              string.IsNullOrEmpty(textureGUID) == false &&
        //              exAtlasDBBasic.Initialized() )
        //         {
        //             exAtlasDBBasic.ElementInfo elInfo = exAtlasDBBasic.GetElementInfoNoInit ( textureGUID );
        //             string path = AssetDatabase.GetAssetPath(atlas_);
        //             string guid = AssetDatabase.AssetPathToGUID(path);

        //             //
        //             if ( elInfo != null ) {
        //                 if ( elInfo.indexInAtlas != index_ || elInfo.guidAtlas != guid ) {
        //                     path = AssetDatabase.GUIDToAssetPath(elInfo.guidAtlas);
        //                     SetSprite( (exAtlas)AssetDatabase.LoadAssetAtPath( path, typeof(exAtlas) ),
        //                                elInfo.indexInAtlas );
        //                     Build(null);
        //                 }
        //             }
        //             else {
        //                 Clear();
        //                 path = AssetDatabase.GUIDToAssetPath(textureGUID);
        //                 Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath( path, typeof(Texture2D) );
        //                 Build(texture);
        //             }
        //         }
        // #endif
        // } DISABLE end

        base.Awake();
        spanim = GetComponent<exSpriteAnimation>();

        if ( atlas_ != null ||
             ( renderer.sharedMaterial != null && renderer.sharedMaterial.mainTexture != null ) )
        {
            meshFilter.sharedMesh = new Mesh();
            ForceUpdateMesh( meshFilter.sharedMesh );
        }
    }
Пример #22
0
 public void init()
 {
     //Cache components
     m_animation       = animation;
     m_spriteAnimation = GetComponent <exSpriteAnimation>();
 }
Пример #23
0
 // Use this for initialization
 void Start()
 {
     sprite = GetComponent <exSprite>();
     anim   = GetComponent <exSpriteAnimation>();
 }
Пример #24
0
    void CalcDirection()
    {
        if (route == null || route.Count == 0)
        {
            return;
        }

        Vector3 target    = route[0];
        Vector3 targetDir = target - transform.position;
        Vector3 forward   = Vector3.right;
        float   angle     = Vector3.Angle(targetDir, forward);
        int     flag      = 0;

        if (angle <= 30)
        {
            flag = 0;
        }
        else if (angle > 150)
        {
            flag = 1;
        }
        else if (angle > 30 && angle <= 90)
        {
            if (target.y >= transform.position.y)
            {
                flag = 2;
            }
            else
            {
                flag = 4;
            }
        }
        else if (angle > 90 && angle <= 150)
        {
            if (target.y > transform.position.y)
            {
                flag = 3;
            }
            else
            {
                flag = 5;
            }
        }

        exSprite          moveSprite = GetComponent <exSprite>();
        exSpriteAnimation moveAnim   = GetComponent <exSpriteAnimation>();
        exSprite          flagSprite = flagCtrl.GetComponent <exSprite>();
        BoxCollider       flagCol    = flagCtrl.GetComponent <BoxCollider>();

        if (flag % 2 == 0)
        {
            if (!isHFlipped)
            {
                isHFlipped = true;
                moveSprite.HFlip();
                flagSprite.HFlip();
                flagCol.center = new Vector3(-flagCol.center.x, flagCol.center.y, flagCol.center.z);
            }
        }
        else
        {
            if (isHFlipped)
            {
                isHFlipped = false;
                moveSprite.HFlip();
                flagSprite.HFlip();
                flagCol.center = new Vector3(-flagCol.center.x, flagCol.center.y, flagCol.center.z);
            }
        }

        Vector3 pos = Vector3.zero;

        flag /= 2;

        switch (state)
        {
        case ArmyState.Running:
            animName = animNames[flag];
            pos      = flagPos[flag];
            break;

        case ArmyState.Escape:
            animName = animNames[flag + 3];
            pos      = flagPos[flag + 6];
            break;

        case ArmyState.Victory:
            animName = animNames[flag + 6];
            pos      = flagPos[flag * 3 + 9];
            break;
        }

        if (!moveAnim.IsPlaying(animName))
        {
            moveAnim.Play(animName);
        }

        if (!isHFlipped)
        {
            pos.x = -pos.x;
        }
        flagCtrl.localPosition = pos;
    }
Пример #25
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    protected new void OnDisable()
    {
        base.OnDisable();

        // NOTE: though we have ExecuteInEditMode, user can Add/Remove spanim in Editor
        if ( spanim == null ) {
            spanim = GetComponent<exSpriteAnimation>();
        }
        // DISABLE {
        // if ( spanim ) {
        //     spanim.Stop();
        // }
        // } DISABLE end
    }
Пример #26
0
 // Use this for initialization
 void Start()
 {
     anim = this.gameObject.GetComponent <exSpriteAnimation>();
 }
Пример #27
0
    void GeneralInit(int gIdx)
    {
        int horseIdx = 0;

        if (gInfo.equipment > 26)
        {
            horseIdx = gInfo.equipment - 26;
        }

        string     str = "";
        GameObject go;

        if (side == WarSceneController.WhichSide.Left)
        {
            str = "Generals/HorseRed/";
        }
        else
        {
            str = "Generals/HorseGreen/";
        }
        str  += "Horse00" + (horseIdx + 1);
        go    = (GameObject)Instantiate(Resources.Load(str));
        horse = go.GetComponent <exSpriteAnimation>();

        if (side == WarSceneController.WhichSide.Left)
        {
            str = "Generals/HeadRed/";
        }
        else
        {
            str = "Generals/HeadGreen/";
        }
        int[,] generalBody = Informations.Instance.generalBody;
        if (generalBody[gIdx, 0] < 9)
        {
            str += "Head0" + (generalBody[gIdx, 0] + 1);
        }
        else
        {
            str += "Head" + (generalBody[gIdx, 0] + 1);
        }
        go   = (GameObject)Instantiate(Resources.Load(str));
        head = go.GetComponent <exSpriteAnimation>();

        if (side == WarSceneController.WhichSide.Left)
        {
            str = "Generals/BodyRed/";
        }
        else
        {
            str = "Generals/BodyGreen/";
        }
        if (generalBody[gIdx, 1] < 9)
        {
            str += "Body0" + (generalBody[gIdx, 1] + 1);
        }
        else
        {
            str += "Body" + (generalBody[gIdx, 1] + 1);
        }
        go   = (GameObject)Instantiate(Resources.Load(str));
        body = go.GetComponent <exSpriteAnimation>();

        if (generalBody[gIdx, 1] < 9)
        {
            str = "Generals/Weapon/Weapon0" + (generalBody[gIdx, 1] + 1);
        }
        else
        {
            str = "Generals/Weapon/Weapon" + (generalBody[gIdx, 1] + 1);
        }
        go     = (GameObject)Instantiate(Resources.Load(str));
        weapon = go.GetComponent <exSpriteAnimation>();

        head.transform.parent   = transform;
        body.transform.parent   = transform;
        weapon.transform.parent = transform;
        horse.transform.parent  = transform;

        head.transform.localPosition   = Vector3.zero;
        body.transform.localPosition   = Vector3.zero;
        weapon.transform.localPosition = new Vector3(0, 0, -5);
        horse.transform.localPosition  = new Vector3(0, 0, 5f);

        head.transform.localScale   = Vector3.one;
        body.transform.localScale   = Vector3.one;
        weapon.transform.localScale = Vector3.one;
        horse.transform.localScale  = Vector3.one;

        head.transform.localRotation   = Quaternion.identity;
        body.transform.localRotation   = Quaternion.identity;
        weapon.transform.localRotation = Quaternion.identity;
        horse.transform.localRotation  = Quaternion.identity;

        if (side == WarSceneController.WhichSide.Right)
        {
            if (WarSceneController.rightGeneralPosition == 0)
            {
                transform.localPosition = generalPosBack;
            }
            else
            {
                transform.localPosition = generalPosFront;
            }
        }
    }
Пример #28
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    protected override void OnEnable()
    {
        base.OnEnable();

        // NOTE: though we have ExecuteInEditMode, user can Add/Remove spanim in Editor
        if ( spanim == null ) {
            spanim = GetComponent<exSpriteAnimation>();
        }
        if ( spanim ) {
            spanim.enabled = true;
        }
    }
Пример #29
0
 ///////////////////////////////////////////////////////////////////////////////
 // functions
 ///////////////////////////////////////////////////////////////////////////////
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 void OnEnable()
 {
     if ( target != editSpAnim ) {
         editSpAnim = target as exSpriteAnimation;
     }
 }
Пример #30
0
 void Start()
 {
     allowFade = false;
     sprite = GetComponent<exSpriteAnimation>();
 }
Пример #31
0
 // Use this for initialization
 void Start()
 {
     myTransform = transform;
     spriteObj = GetComponent<exSprite>();
     spriteAnimation = GetComponent<exSpriteAnimation>();
 }
Пример #32
0
 // Use this for initialization
 void Start()
 {
     sprite = transform.GetChild(0).GetComponent <exSprite>();
     anim   = transform.GetChild(0).GetComponent <exSpriteAnimation>();
 }
Пример #33
0
 // Use this for initialization
 void Start()
 {
     anim = this.gameObject.GetComponent<exSpriteAnimation>();
 }
Пример #34
0
    // ------------------------------------------------------------------
    /// \param _spAnim send message to target _spAnim.gameObject
    /// \param _lastAnim last animation state
    /// \param _lastIndex last triggered event info index (-1 means from start)
    /// \param _start the start time in seconds
    /// \param _delta the delta time in seconds
    /// \param _wrapMode  the wrap mode
    /// \return return the last triggered event index
    /// Trigger events locate between the start and start+_delta time span
    // ------------------------------------------------------------------

    public int TriggerEvents(exSpriteAnimation _spAnim,
                             exSpriteAnimState _lastAnim,
                             int _lastIndex,
                             float _start,
                             float _delta,
                             WrapMode _wrapMode)
    {
        if (eventInfos.Count == 0)
        {
            return(-1);
        }
        if (_delta == 0.0f)
        {
            return(-1);
        }

        // WrapSeconds
        float t = WrapSeconds(_start, _wrapMode);

        // if we are the just start playing
        if (_lastIndex == -1)
        {
            return(ForwardTriggerEvents(_spAnim, _lastAnim, -1, t, t + _delta, true));
        }

        //
        if (_wrapMode == WrapMode.PingPong)
        {
            int cnt = (int)(_start / length);
            if (cnt % 2 == 1)
            {
                _delta = -_delta;
            }
        }

        // if we are play forward
        if (_delta > 0.0f)
        {
            if (t + _delta > length)
            {
                if (_wrapMode == WrapMode.Loop)
                {
                    float rest = t + _delta - length;
                    ForwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, length, false);
                    exSpriteAnimState curAnim = _spAnim.GetCurrentAnimation();
                    if (curAnim == null || _lastAnim != curAnim)
                    {
                        return(-1);
                    }
                    return(ForwardTriggerEvents(_spAnim, _lastAnim, -1, 0.0f, rest, true));
                }
                else if (_wrapMode == WrapMode.PingPong)
                {
                    float rest = t + _delta - length;
                    ForwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, length, false);
                    exSpriteAnimState curAnim = _spAnim.GetCurrentAnimation();
                    if (curAnim == null || _lastAnim != curAnim)
                    {
                        return(-1);
                    }
                    return(BackwardTriggerEvents(_spAnim, _lastAnim, eventInfos.Count, length, length - rest, false));
                }
                else
                {
                    return(ForwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, t + _delta, false));
                }
            }
            else
            {
                return(ForwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, t + _delta, false));
            }
        }
        else
        {
            if (t + _delta < 0.0f)
            {
                if (_wrapMode == WrapMode.Loop)
                {
                    float rest = 0.0f - (t + _delta);
                    BackwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, 0.0f, false);
                    exSpriteAnimState curAnim = _spAnim.GetCurrentAnimation();
                    if (curAnim == null || _lastAnim != curAnim)
                    {
                        return(-1);
                    }
                    return(BackwardTriggerEvents(_spAnim, _lastAnim, eventInfos.Count, length, length - rest, true));
                }
                else if (_wrapMode == WrapMode.PingPong)
                {
                    float rest = 0.0f - (t + _delta);
                    BackwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, 0.0f, false);
                    exSpriteAnimState curAnim = _spAnim.GetCurrentAnimation();
                    if (curAnim == null || _lastAnim != curAnim)
                    {
                        return(-1);
                    }
                    return(ForwardTriggerEvents(_spAnim, _lastAnim, -1, 0.0f, rest, false));
                }
                else
                {
                    return(BackwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, t + _delta, false));
                }
            }
            else
            {
                return(BackwardTriggerEvents(_spAnim, _lastAnim, _lastIndex, t, t + _delta, false));
            }
        }
    }
Пример #35
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    protected new void Awake()
    {
        // DISABLE {
        // #if UNITY_EDITOR
        //         if ( EditorApplication.isPlaying == false &&
        //              string.IsNullOrEmpty(textureGUID) == false &&
        //              exAtlasDBBasic.Initialized() )
        //         {
        //             exAtlasDBBasic.ElementInfo elInfo = exAtlasDBBasic.GetElementInfoNoInit ( textureGUID );
        //             string path = AssetDatabase.GetAssetPath(atlas_);
        //             string guid = AssetDatabase.AssetPathToGUID(path);

        //             //
        //             if ( elInfo != null ) {
        //                 if ( elInfo.indexInAtlas != index_ || elInfo.guidAtlas != guid ) {
        //                     path = AssetDatabase.GUIDToAssetPath(elInfo.guidAtlas);
        //                     SetSprite( (exAtlas)AssetDatabase.LoadAssetAtPath( path, typeof(exAtlas) ),
        //                                elInfo.indexInAtlas );
        //                     Build(null);
        //                 }
        //             }
        //             else {
        //                 Clear();
        //                 path = AssetDatabase.GUIDToAssetPath(textureGUID);
        //                 Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath( path, typeof(Texture2D) );
        //                 Build(texture);
        //             }
        //         }
        // #endif
        // } DISABLE end

        base.Awake();
        spanim = GetComponent<exSpriteAnimation>();

        if ( atlas_ != null ||
             ( renderer.sharedMaterial && renderer.sharedMaterial.mainTexture != null ) )
        {
            if ( meshFilter ) {
                // create mesh ( in editor, this can duplicate mesh to prevent shared mesh for sprite)
                meshFilter_.mesh = new Mesh();
                meshFilter_.sharedMesh.hideFlags = HideFlags.DontSave;
                ForceUpdateMesh( meshFilter_.sharedMesh );

                // check if update mesh collider
                MeshCollider meshCollider = collider as MeshCollider;
                if ( meshCollider && meshCollider.sharedMesh == null ) {
                    this.UpdateColliderSize(0.2f);
                }
            }
        }
    }
Пример #36
0
 public void init()
 {
     m_animation = GetComponent <exSpriteAnimation>();
 }