// CALLBACK

        private void OnRemovedRigidbody(IBody i_Body)
        {
            GameObject go = PhysicsManager.GetGameObject(i_Body);

            if (go != null)
            {
                TrueSyncObject trueSyncObject = go.GetComponent <TrueSyncObject>();
                if (trueSyncObject != null)
                {
                    m_TsBehaviourCache.Clear();
                    for (int index = 0; index < trueSyncObject.behaviourCount; ++index)
                    {
                        TrueSyncBehaviour behaviour = trueSyncObject.GetTrueSyncBehaviourByIndex(index);
                        if (behaviour != null)
                        {
                            m_TsBehaviourCache.Add(behaviour);
                        }
                    }

                    RemoveFromTSMBList(m_QueuedBehaviours, m_TsBehaviourCache);
                    RemoveFromTSMBList(m_GeneralBehaviours, m_TsBehaviourCache);

                    foreach (List <TrueSyncManagedBehaviour> list in m_BehavioursPerPlayer.Values)
                    {
                        RemoveFromTSMBList(list, m_TsBehaviourCache);
                    }

                    m_TsBehaviourCache.Clear();
                }
            }
        }
        public void RegisterTrueSyncObject(TrueSyncObject i_TrueSyncObject)
        {
            if (i_TrueSyncObject == null)
            {
                return;
            }

            // Add True Sync Behaviours to QueuedBehaviours.

            for (int index = 0; index < i_TrueSyncObject.behaviourCount; ++index)
            {
                TrueSyncBehaviour trueSyncBehaviour = i_TrueSyncObject.GetTrueSyncBehaviourByIndex(index);

                if (trueSyncBehaviour == null)
                {
                    continue;
                }

                TrueSyncManagedBehaviour trueSyncManagedBehaviour = NewManagedBehavior(trueSyncBehaviour);
                m_QueuedBehaviours.Add(trueSyncManagedBehaviour);
            }

            // Initialize Object.

            InitializeObject(i_TrueSyncObject);

            // Callback

            i_TrueSyncObject.OnRegistration();
        }
 public static void RegisterTrueSyncObjectMain(TrueSyncObject i_TrueSyncObject)
 {
     if (m_Instance != null)
     {
         m_Instance.RegisterTrueSyncObject(i_TrueSyncObject);
     }
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            TrueSyncObject tsObject = target as TrueSyncObject;

            if (tsObject == null)
            {
                return;
            }

            GameObject go = tsObject.gameObject;

            if (go == null)
            {
                return;
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Info", EditorStyles.boldLabel);

            if (!EditorApplication.isPlaying)
            {
                TSTransform2D[]     tsTransforms2D = go.GetComponentsInChildren <TSTransform2D>();
                TSCollider2D[]      tsColliders2D  = go.GetComponentsInChildren <TSCollider2D>();
                TrueSyncBehaviour[] tsBehaviours   = go.GetComponentsInChildren <TrueSyncBehaviour>();

                int transformCount = (tsTransforms2D != null) ? tsTransforms2D.Length : 0;
                int colliderCount  = (tsColliders2D != null) ? tsColliders2D.Length : 0;
                int behaviourCount = (tsBehaviours != null) ? tsBehaviours.Length : 0;

                EditorGUILayout.LabelField("Transforms (" + transformCount + ")", EditorStyles.label);
                EditorGUILayout.LabelField("Colliders (" + colliderCount + ")", EditorStyles.label);
                EditorGUILayout.LabelField("Behaviours (" + behaviourCount + ")", EditorStyles.label);
            }
            else
            {
                int transformCount = (tsObject != null) ? tsObject.transformCount: 0;
                int colliderCount  = (tsObject != null) ? tsObject.colliderCount: 0;
                int behaviourCount = (tsObject != null) ? tsObject.behaviourCount: 0;

                int registeredTransformCount = (tsObject != null) ? tsObject.registeredTransformCount : 0;
                int registeredColliderCount  = (tsObject != null) ? tsObject.registeredColliderCount : 0;
                int registeredBehaviourCount = (tsObject != null) ? tsObject.registeredBehaviourCount : 0;

                EditorGUILayout.LabelField("Transforms (" + transformCount + " / " + registeredTransformCount + ")", EditorStyles.label);
                EditorGUILayout.LabelField("Colliders (" + colliderCount + " / " + registeredColliderCount + ")", EditorStyles.label);
                EditorGUILayout.LabelField("Behaviours (" + behaviourCount + " / " + registeredBehaviourCount + ")", EditorStyles.label);
            }
        }
        private void InitializeObject(TrueSyncObject i_TrueSyncObject)
        {
            if (i_TrueSyncObject == null)
            {
                return;
            }

            // Register colliders on physics manager.

            for (int index = 0; index < i_TrueSyncObject.colliderCount; ++index)
            {
                TSCollider2D collider = i_TrueSyncObject.GetColliderByIndex(index);

                if (collider == null)
                {
                    continue;
                }

                PhysicsManager.AddBody(collider);
            }

            // Init transforms.

            for (int index = 0; index < i_TrueSyncObject.transformCount; ++index)
            {
                TSTransform2D t = i_TrueSyncObject.GetTransformByIndex(index);

                if (t == null)
                {
                    continue;
                }

                t.Initialize();
            }

            // Init rigidbody, if any.

            for (int index = 0; index < i_TrueSyncObject.rigidbodyCount; ++index)
            {
                TSRigidBody2D rigidbody = i_TrueSyncObject.GetRigidBodyByIndex(index);

                if (rigidbody == null)
                {
                    continue;
                }

                rigidbody.Initialize();
            }
        }
        public void RegisterTrueSyncObject(GameObject i_Go)
        {
            if (i_Go == null)
            {
                return;
            }

            // Get TrueSyncObject

            TrueSyncObject trueSyncObject = i_Go.GetComponent <TrueSyncObject>();

            if (trueSyncObject == null)
            {
                return;
            }

            // Register true sync object.

            RegisterTrueSyncObject(trueSyncObject);
        }