Exemplo n.º 1
0
        public static void RecordTransform(Transform target, Transform parent = null, int siblingIndex = -1)
        {
            if (!Enabled)
            {
                return;
            }

            TransformRecord transformRecord = new TransformRecord {
                position = target.position, rotation = target.rotation, scale = target.localScale
            };

            transformRecord.parent       = parent;
            transformRecord.siblingIndex = siblingIndex;

            RecordObject(target, transformRecord, record =>
            {
                Transform transform = (Transform)record.Target;
                if (!transform)
                {
                    return(false);
                }

                TransformRecord state = (TransformRecord)record.State;
                bool hasChanged       = transform.position != state.position ||
                                        transform.rotation != state.rotation ||
                                        transform.localScale != state.scale;

                bool trsOnly = state.siblingIndex == -1;
                if (!trsOnly)
                {
                    hasChanged = hasChanged || transform.parent != state.parent || transform.GetSiblingIndex() != state.siblingIndex;
                }

                if (hasChanged)
                {
                    Transform prevParent = transform.parent;
                    if (!trsOnly)
                    {
                        transform.SetParent(state.parent, true);
                        transform.SetSiblingIndex(state.siblingIndex);
                    }

                    transform.position   = state.position;
                    transform.rotation   = state.rotation;
                    transform.localScale = state.scale;
                }
                return(hasChanged);
            },
                         record => { });
        }
Exemplo n.º 2
0
        protected void LateUpdate()
        {
#pragma warning disable 162
            if (Constants.DEBUG_COMBINE_STATIC_BATCH_TRANFORM)
            {
                for (int iGameObject = 0; iGameObject < m_StaticBatchGameObjects.Length; iGameObject++)
                {
                    if (!TransformRecord.Equals(m_TransfromRecords[iGameObject], m_StaticBatchGameObjects[iGameObject].transform))
                    {
                        Leyoutech.Utility.DebugUtility.LogWarning(Constants.LOG_TAG
                                                                  , string.Format("CombineStaticBatch.m_StaticBatchGameObjects index({0}) transfrom has changed in ({0})"
                                                                                  , iGameObject
                                                                                  , Leyoutech.Utility.ObjectUtility.CalculateTransformPath(transform))
                                                                  , gameObject);
                    }
                }
            }
#pragma warning restore 162
        }
Exemplo n.º 3
0
 public static bool Equals(TransformRecord a, TransformRecord b)
 {
     return(a.LocalPosition == b.LocalPosition &&
            a.LocalScale == b.LocalScale &&
            a.LocalRotation == b.LocalRotation);
 }
Exemplo n.º 4
0
 public static bool Equals(TransformRecord a, Transform b)
 {
     return(Equals(a, new TransformRecord(b)));
 }
Exemplo n.º 5
0
        protected void Awake()
        {
            List <GameObject> staticBatchGameObjects = new List <GameObject>();

            switch (MyCombineType)
            {
            case CombineType.AllChildren:
                Leyoutech.Utility.ObjectUtility.CollectAllChildren(staticBatchGameObjects, transform, true);
                break;

            case CombineType.AllChildrenWithoutDeactivate:
                Leyoutech.Utility.ObjectUtility.CollectAllChildren(staticBatchGameObjects, transform, false);
                break;

            case CombineType.Specified:
                if (SpecifiedGameObjects != null)
                {
                    for (int iSpecified = 0; iSpecified < SpecifiedGameObjects.Length; iSpecified++)
                    {
                        GameObject iterGameObject = SpecifiedGameObjects[iSpecified];
                        if (iterGameObject == null)
                        {
                            Leyoutech.Utility.DebugUtility.LogError(Constants.LOG_TAG
                                                                    , string.Format("CombineStaticBatch.SpecifiedGameObjects index({0}) is null in ({1})"
                                                                                    , iSpecified
                                                                                    , Leyoutech.Utility.ObjectUtility.CalculateTransformPath(transform))
                                                                    , gameObject);
                            continue;
                        }

                        if (!iterGameObject.transform.IsChildOf(transform))
                        {
                            Leyoutech.Utility.DebugUtility.LogError(Constants.LOG_TAG
                                                                    , string.Format("CombineStaticBatch.SpecifiedGameObjects index({0}) is not a child of ({1})"
                                                                                    , iSpecified
                                                                                    , Leyoutech.Utility.ObjectUtility.CalculateTransformPath(transform))
                                                                    , iterGameObject);
                            continue;
                        }

                        staticBatchGameObjects.Add(iterGameObject);
                    }
                }
                else
                {
                    Leyoutech.Utility.DebugUtility.LogError(Constants.LOG_TAG
                                                            , string.Format("CombineStaticBatch.SpecifiedGameObjects is null in ({0})"
                                                                            , Leyoutech.Utility.ObjectUtility.CalculateTransformPath(transform))
                                                            , gameObject);
                }
                break;

            default:
                Leyoutech.Utility.DebugUtility.Assert(false, Constants.LOG_TAG, "Not support CombineType: " + MyCombineType);
                break;
            }

            if (staticBatchGameObjects.Count == 0)
            {
                Leyoutech.Utility.DebugUtility.LogWarning(Constants.LOG_TAG
                                                          , string.Format("CombineStaticBatch.staticBatchGameObjects count is zero in ({0})"
                                                                          , Leyoutech.Utility.ObjectUtility.CalculateTransformPath(transform))
                                                          , gameObject);
            }

            m_StaticBatchGameObjects = staticBatchGameObjects.ToArray();
#if UNITY_EDITOR
            if (Constants.ENABLE_COMBINE_STATIC_BATCH_COMBINE)
#endif
            {
#pragma warning disable 162
#if UNITY_EDITOR
                long startTicks = Leyoutech.Utility.DebugUtility.GetTicksSinceStartup();
#endif
                StaticBatchingUtility.Combine(m_StaticBatchGameObjects, gameObject);
#if UNITY_EDITOR
                long elapsedTicks = Leyoutech.Utility.DebugUtility.GetTicksSinceStartup() - startTicks;
#endif
                Leyoutech.Utility.DebugUtility.Log(Constants.LOG_TAG
                                                   , string.Format("CombineStaticBatch.Combine staticBatch count:{0} in ({1})"
                                                                   , m_StaticBatchGameObjects.Length
                                                                   , gameObject.name)
#if UNITY_EDITOR
                                                   + string.Format(" Elapsed {0:F3} ms", (elapsedTicks / 10000.0))
#endif
                                                   , gameObject);
#pragma warning restore 162
            }


#pragma warning disable 162
            if (Constants.DEBUG_COMBINE_STATIC_BATCH_TRANFORM)
            {
                m_TransfromRecords = new TransformRecord[m_StaticBatchGameObjects.Length];
                for (int iGameObject = 0; iGameObject < m_StaticBatchGameObjects.Length; iGameObject++)
                {
                    m_TransfromRecords[iGameObject] = new TransformRecord(m_StaticBatchGameObjects[iGameObject].transform);
                }
            }
            else
            {
                Destroy(this);
            }
#pragma warning restore 162
        }