/// <summary>
    /// undo all replace operations
    /// </summary>
    public static void UndoAllReplace(CutsceneController cc)
    {
        for (var ie = cc.m_ReplRecord.GetEnumerator(); ie.MoveNext();)
        {
            var        pr    = ie.Current;
            GameObject extGO = pr.Key;
            //Transform extTr = extGO.transform;
            ReplData rData = pr.Value;

            //Dbg.Log("Undo Replace: extGO: {0}", rData.m_ExtGOOrigName);

            //1
            extGO.name = rData.m_ExtGOOrigName;


            //3
            if (rData.m_ExtGOOrigParent)
            {
                Misc.AddChild(rData.m_ExtGOOrigParent, extGO);
            }
            else
            {
                extGO.transform.parent = null;
            }

            //2
            if (rData.m_RevertPose)
            {
                _ExecuteRevertPose(rData);
            }

            //4
            if (rData.m_IntGO)
            {
                if (cc.m_BlendOutTime < 0)
                {
                    rData.m_IntGO.SetActive(true);
                }
                rData.m_IntGO.name = rData.m_IntGO.name.Substring(1);
            }

            //5
            if (rData.m_ReEnableAnimator)
            {
                _SetAnimatorEnableState(extGO, true);
            }

            //6. prepare blend-out
            if (cc.m_BlendOutTime >= 0)
            {
                BlendOutData boData = new BlendOutData();
                boData.m_InternalGO      = rData.m_IntGO;
                cc.m_BlendOutCtrl[extGO] = boData;
                cc._PrepareBlend(extGO.transform, boData.m_BlendDataLst);
            }
        }

        cc.m_ReplRecord.Clear();
        cc.m_ToSwapObjPairs.Clear();
    }
    // public method

    /// <summary>
    /// given an external GO (X) outside the CC,
    /// replace the GO (Y) inside CC with X, and change X's name to be Y's name
    ///
    /// this could be used to change the character appearance during cut-scene playing
    /// </summary>
    public void SwapGO(GameObject extGO, GameObject intGO, bool bRevertPoseAtEnd, bool bReEnableAnimator)
    {
        Transform extTr = extGO.transform;
        ReplData  rData = new ReplData();

        rData.m_ExtGOOrigName    = extGO.name;
        rData.m_ExtGOOrigParent  = extTr.parent;
        rData.m_IntGO            = intGO;
        rData.m_RevertPose       = bRevertPoseAtEnd;
        rData.m_ReEnableAnimator = bReEnableAnimator;
        var blendInDataBasedOnCC = rData.m_ExtGOTrDataBasedOnCC = new XformData();

        m_ReplRecord.Add(extGO, rData);

        intGO.SetActive(false);
        extGO.name = intGO.name;
        intGO.name = "_" + intGO.name; //make intGO a different name

        if (m_BlendInTime > 0 || rData.m_RevertPose)
        {
            _PrepareBlend(extTr, rData.m_ExtGOBlendData);
        }

        Misc.AddChild(intGO.transform.parent, extGO); // but UndoAllReplace needs localPosition based on old parent's transform

        blendInDataBasedOnCC.CopyFrom(extTr);         // blend-in needs localposition based on CC's transform
        extGO.transform.CopyLocal(intGO.transform);

        _SetAnimatorEnableState(extGO, false);
    }
        private void Msg_CaughtTheCube()
        {
            m_Parabola.Stop();

            Misc.AddChild(m_PlayerRightHand, m_CubeTr);

            Dbg.Log("Caught cube");

            m_bCubeThrown = false;

            CutsceneController.JumpToTimeTag(m_CC, "GotCube");
        }
Esempio n. 4
0
        public GameObject Spawn()
        {
            Dbg.Assert(m_prefab != null, "PrefabPool.Spawn: prefab is null");
            Dbg.Assert(m_poolName != null, "PrefabPool.Spawn: poolName is null");

            GameObject spawned = _FindInactiveGO();

            if (spawned == null)
            {
                spawned      = Instantiate(m_prefab) as GameObject;
                spawned.name = m_prefab.name;

                m_cont.Add(spawned);
                //Misc.AddChild(gameObject, spawned); //commented-out: no meaning to change the parent relation, would cause OnTransformParentChanged\
                if (m_warnSize > 0 && m_cont.Count >= m_warnSize)
                {
                    Dbg.LogWarn("PrefabPool.Spawn: pool {0} has {1} elements, limit is {2}", m_poolName, m_cont.Count, m_warnSize);
                }

                //Dbg.Log("pool {0} instantiated a {1}, m_cont: {2}", m_poolName, m_prefab.name, m_cont.Count);
            }


            // NOTE: it's important to remove from pool BEFORE activating it
            // as NGUI has a petty behavior that would move any pool that has a ACTIVE UI element to be a child of UIRoot
            Misc.AddChild((Transform)null, spawned); //remove spawned from pool's GO,

            spawned.SetActive(true);                 //set it to in use

            var option = spawned.GetComponent <PoolTicketOption>();

            if (option && option.broadcastSpawnMsg)
            {
                spawned.BroadcastMessage("OnSpawn", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                spawned.SendMessage("OnSpawn", SendMessageOptions.DontRequireReceiver); //SendMsg won't send to inactive obj
            }

            // get PoolTicket, fill in this pool so it can be despawn from the object
            PoolTicket ticket = spawned.ForceGetComponent <PoolTicket>();

            ticket.Pool    = this;
            ticket.IsAvail = false;


            return(spawned);
        }
Esempio n. 5
0
        // public method

        public override void OnAnimEvent()
        {
            Transform ccroot = m_CC.transform;

            for (int idx = 0; idx < m_SpawnDataLst.Count; ++idx)
            {
                CCSpawnData sd = m_SpawnDataLst[idx];
                GameObject  go = sd.Spawn(ccroot);

                Transform newTr = go.transform;
                if (newTr.parent == null)
                {
                    Misc.AddChild(transform, go);
                }
            }
        }
Esempio n. 6
0
        public void Despawn(object obj)
        {
            GameObject go = obj as GameObject;

            Dbg.Assert(go != null, "PrefabPool.Despawn: not a gameobject");

            int idx = m_cont.IndexOf(go);

            if (!m_bAllowDespawnExtObj)
            {
                Dbg.Assert(idx != -1, "PrefabPool.Despawn: cannot find given object in container");
            }
            else
            {
                if (idx == -1)
                {
                    m_cont.Add(go);
#if PREFABPOOL_LOG
                    Dbg.Log("PrefabPool.Despawn: an external object is despawned into pool \"{0}\", name: {1}", m_poolName, go.name);
#endif
                }
            }

            PoolTicket ticket = go.ForceGetComponent <PoolTicket>();
            ticket.Pool    = this;
            ticket.IsAvail = true;
            Dbg.Assert(ticket.RefCnt == 0, "PrefabPool.Despawn: the refCnt is {0}, should be zero: '{1}'", ticket.RefCnt, ticket.name);
            ticket.RefCnt = 0;

            PoolTicketOption option = go.GetComponent <PoolTicketOption>();

            if (option && option.broadcastDespawnMsg)
            {
                go.BroadcastMessage("OnDespawn", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                go.SendMessage("OnDespawn", SendMessageOptions.DontRequireReceiver);
            }

            go.SetActive(false);                  // it's important to deactivate before add to pool, BECAUSE OF NGUI

            Misc.AddChild(gameObject, go, false); //use false because we want to ensure the world-pos/scale/rot not changed after add to the pool
        }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(m_ScriptProp);

        GameObject prefabGO = (GameObject)EditorGUILayout.ObjectField("Dialog GO Prefab", m_GUIPrefabProp.objectReferenceValue, typeof(GameObject), false);

        if (prefabGO != m_GUIPrefabProp.objectReferenceValue)
        {
            GameObject newGO = PrefabUtility.InstantiatePrefab(prefabGO) as GameObject;
            GameObject oldGO = (GameObject)m_GUIPrefabProp.objectReferenceValue;
            m_GUIPrefabProp.objectReferenceValue = newGO;
            Misc.AddChild(((MonoBehaviour)serializedObject.targetObject).transform, newGO);
            GameObject.DestroyImmediate(oldGO);
        }

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 8
0
        private static PrefabPool _CreatePoolByPrefab(GameObject prefab)
        {
#if PREFABPOOL_LOG
            Dbg.LogWarn("Prefab._CreatePoolByPrefab: {0}", prefab.name);
#endif

            string     poolName  = prefab.name + "Pool_" + prefab.GetInstanceID();
            GameObject newPoolGO = new GameObject(poolName);
            PrefabPool pool      = newPoolGO.AddComponent <PrefabPool>();
            pool.Prefab             = prefab;
            pool.Name               = poolName;
            pool.AllowDespawnExtObj = true;
            pool.RegToMgr();

            GameObject prefabPools = GameObject.FindGameObjectWithTag(TAG_PREFABPOOLS);
            if (prefabPools == null)
            {
                prefabPools     = new GameObject("PrefabPools");
                prefabPools.tag = TAG_PREFABPOOLS;
            }
            Misc.AddChild(prefabPools, newPoolGO);

            return(pool);
        }
Esempio n. 9
0
    /// <summary>
    /// make the AnimEvent and EventGO to be matched
    /// maybe not one-one match, multiple animEvent could match same EventGO
    /// </summary>
    private void _MatchEventGOAndAnimEvent()
    {
        //////////////////////////////////////////////////
        //  1. for each AnimEvent, if there is not a corresponding eventGO, create it;
        //  2. for each eventGO, if there is not a corresponding AnimEvent, the delete the eventGO
        //////////////////////////////////////////////////

        //if( _IsAnimEventPopupOpen() )
        //{
        //    return; //don't execute matching if the AnimEventPopup is open
        //}

        // create a Dictionary for eventGO
        for (int idx = 0; idx < m_evtGoRoot.childCount; ++idx)
        {
            Transform ctr = m_evtGoRoot.GetChild(idx);
            m_evtGORefDict[ctr] = false;
        }

        // get the AnimEvent list
        AnimationEvent[] events = AnimationUtility.GetAnimationEvents(m_CurClip);

        // step 1
        for (int idx = 0; idx < events.Length; ++idx)
        {
            AnimationEvent evt      = events[idx];
            string         goName   = evt.stringParameter;
            string         funcName = evt.functionName;

            if (goName == null)
            {
                Dbg.LogWarn("CCEditor._MatchEventGOAndAnimEvent: found an event not specifying the GOName, at time: {0}", evt.time);
                ArrayUtility.RemoveAt(ref events, idx);
                --idx;
            }

            Transform oneTr = m_evtGoRoot.Find(goName);
            if (null == oneTr)
            {
                //create the go
                GameObject newEvtGO = new GameObject(goName);
                Misc.AddChild(m_evtGoRoot, newEvtGO);
                Dbg.Log("Sync AnimEvent with EventGO: create EventGO for: {0}", goName);

                //add component according to the funcName, the init-work should be executed by the MB's awake() or start()
                //CC_EvtActions newAct = newEvtGO.AddComponent("CC_" + funcName) as CC_EvtActions;
                //Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController");
                //newAct.CC = m_CC;

                string tpName = "MH.CC_" + funcName;
                Type   tp     = RCall.GetTypeFromString(tpName);
                Dbg.Assert(tp != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get type from string: {0}", tpName);
                CC_EvtActions newAct = newEvtGO.AddComponent(tp) as CC_EvtActions;
                Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController");
                newAct.CC = m_CC;
            }
            else
            {
                m_evtGORefDict[oneTr] = true; //this event go is ref-ed, don't delete it
            }
        }

        // step 2
        for (var ie = m_evtGORefDict.GetEnumerator(); ie.MoveNext();)
        {
            var  pr    = ie.Current;
            bool inUse = pr.Value;
            if (!inUse)
            {
                Transform tr = pr.Key;
                Dbg.Log("Sync AnimEvent with EventGO: delete EventGO: {0}", tr.name);
                GameObject.DestroyImmediate(tr.gameObject);
            }
        }

        m_evtGORefDict.Clear(); //clear the tmp data
    }
Esempio n. 10
0
        public GameObject Spawn(SpawnData data)
        {
            Dbg.Assert(m_prefab != null, "PrefabPool.Spawn: prefab is null");
            Dbg.Assert(m_poolName != null, "PrefabPool.Spawn: poolName is null");

            GameObject spawned = _FindInactiveGO();

            if (spawned == null)
            {
                var pfTr = m_prefab.transform;
                switch (data.flags)
                {
                case SpawnData.None: spawned = (GameObject)Instantiate(m_prefab, pfTr.position, pfTr.rotation); break;

                case SpawnData.Pos: spawned = (GameObject)Instantiate(m_prefab, data.pos, pfTr.rotation); break;

                case SpawnData.Rot: spawned = (GameObject)Instantiate(m_prefab, pfTr.position, data.rot); break;

                case SpawnData.PR: spawned = (GameObject)Instantiate(m_prefab, data.pos, data.rot); break;

                case SpawnData.Tr: spawned = (GameObject)Instantiate(m_prefab, pfTr.position, pfTr.rotation); break;

                case SpawnData.Tr | SpawnData.Pos: spawned = (GameObject)Instantiate(m_prefab, data.pos, pfTr.rotation); break;

                case SpawnData.Tr | SpawnData.Pos | SpawnData.Rot: spawned = (GameObject)Instantiate(m_prefab, data.pos, data.rot); break;

                default: Dbg.LogErr("PrefabPool.Spawn: unexpected flags: {0}", data.flags); break;
                }

                spawned.name = m_prefab.name;

                m_cont.Add(spawned);

                if (m_warnSize > 0 && m_cont.Count >= m_warnSize)
                {
                    Dbg.LogWarn("PrefabPool.Spawn: pool {0} has {1} elements, limit is {2}", m_poolName, m_cont.Count, m_warnSize);
                }

                //Dbg.Log("pool {0} instantiated a {1}, m_cont: {2}", m_poolName, m_prefab.name, m_cont.Count);
            }
            else
            {
                var tr = spawned.transform;
                if (data.HasPos())
                {
                    tr.position = data.pos;
                }
                if (data.HasRot())
                {
                    tr.rotation = data.rot;
                }
            }


            // NOTE: it's important to remove from pool BEFORE activating it
            // as NGUI has a petty behavior that would move any pool that has a ACTIVE UI element to be a child of UIRoot
            if (data.HasTr())
            {
                Misc.AddChild(data.tr, spawned);
            }
            else
            {
                Misc.AddChild((Transform)null, spawned);
            }

            spawned.SetActive(true); //set it to in use

            var option = spawned.GetComponent <PoolTicketOption>();

            if (option && option.broadcastSpawnMsg)
            {
                spawned.BroadcastMessage("OnSpawn", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                spawned.SendMessage("OnSpawn", SendMessageOptions.DontRequireReceiver); //SendMsg won't send to inactive obj
            }

            // get PoolTicket, fill in this pool so it can be despawn from the object
            PoolTicket ticket = spawned.ForceGetComponent <PoolTicket>();

            ticket.Pool    = this;
            ticket.IsAvail = false;

            return(spawned);
        }