예제 #1
0
        /// <summary>
        /// Searches the parent scene object hierarchy to find a parent Rigidbody component.
        /// </summary>
        protected void UpdateParentRigidbody()
        {
            if (serializableData.isTrigger)
            {
                SetRigidbody(null);
                return;
            }

            SceneObject currentSO = SceneObject;

            while (currentSO != null)
            {
                Rigidbody parent = currentSO.GetComponent <Rigidbody>();
                if (parent != null)
                {
                    if (currentSO.Active && IsValidParent(parent))
                    {
                        SetRigidbody(parent);
                    }
                    else
                    {
                        SetRigidbody(null);
                    }

                    return;
                }

                currentSO = currentSO.Parent;
            }

            // Not found
            SetRigidbody(null);
        }
예제 #2
0
        /// <summary>
        /// Attempts to find the parent <see cref="Animation"/> component and registers itself with it.
        /// </summary>
        private void UpdateParentAnimation()
        {
            SceneObject currentSO = SceneObject;

            while (currentSO != null)
            {
                Animation parent = currentSO.GetComponent <Animation>();
                if (parent != null)
                {
                    if (currentSO.Active)
                    {
                        SetParent(parent);
                    }
                    else
                    {
                        SetParent(null);
                    }

                    return;
                }

                currentSO = currentSO.Parent;
            }

            SetParent(null);
        }
예제 #3
0
        /// <summary>
        /// Searches child scene objects for <see cref="Bone"/> components and returns any found ones.
        /// </summary>
        private Bone[] FindChildBones()
        {
            Stack <SceneObject> todo = new Stack <SceneObject>();

            todo.Push(SceneObject);

            List <Bone> bones = new List <Bone>();

            while (todo.Count > 0)
            {
                SceneObject currentSO = todo.Pop();

                Bone bone = currentSO.GetComponent <Bone>();
                if (bone != null)
                {
                    bone.SetParent(this, true);
                    bones.Add(bone);
                }

                int childCount = currentSO.GetNumChildren();
                for (int i = 0; i < childCount; i++)
                {
                    SceneObject child = currentSO.GetChild(i);
                    if (child.GetComponent <Animation>() != null)
                    {
                        continue;
                    }

                    todo.Push(child);
                }
            }

            return(bones.ToArray());
        }
예제 #4
0
 private void OnInitialize()
 {
     animation = SceneObject.GetComponent <Animation>();
     if (animation != null)
     {
         RegisterAnimation(animation);
         animation.RegisterRenderable(this);
     }
 }
예제 #5
0
        private void OnReset()
        {
            if (impl != null)
            {
                impl.Destroy();
            }

            Camera cam = SceneObject.GetComponent <Camera>();

            impl = new ProfilerOverlayInternal(cam);
        }
예제 #6
0
        /// <summary>
        /// Searches child scene objects for Collider components and attaches them to the rigidbody. Make sure to call
        /// <see cref="ClearColliders"/> if you need to clear old colliders first.
        /// </summary>
        private void UpdateColliders()
        {
            Stack <SceneObject> todo = new Stack <SceneObject>();

            todo.Push(SceneObject);

            while (todo.Count > 0)
            {
                SceneObject currentSO = todo.Pop();

                if (currentSO.GetComponent <Collider>() != null)
                {
                    Collider[] colliders = currentSO.GetComponents <Collider>();
                    foreach (var entry in colliders)
                    {
                        if (!entry.IsValidParent(this))
                        {
                            continue;
                        }

                        if (entry.native == null)
                        {
                            continue;
                        }

                        entry.SetRigidbody(this, true);
                        entry.native.Rigidbody = native;

                        children.Add(entry);
                        native.AddCollider(entry);
                    }
                }

                int childCount = currentSO.GetNumChildren();
                for (int i = 0; i < childCount; i++)
                {
                    SceneObject child = currentSO.GetChild(i);

                    if (child.GetComponent <Rigidbody>() != null)
                    {
                        continue;
                    }

                    todo.Push(child);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Checks if the rigidbody is nested under another rigidbody, and throws out a warning if so.
        /// </summary>
        private void CheckForNestedRigibody()
        {
            SceneObject currentSO = SceneObject.Parent;

            while (currentSO != null)
            {
                if (currentSO.GetComponent <Rigidbody>() != null)
                {
                    Debug.LogWarning("Nested Rigidbodies detected. This will result in inconsistent transformations. " +
                                     "To parent one Rigidbody to another move its colliders to the new parent, but remove the " +
                                     "Rigidbody component.");
                    return;
                }

                currentSO = currentSO.Parent;
            }
        }
예제 #8
0
        /// <summary>
        /// Creates the internal representation of the animation and restores the values saved by the component.
        /// </summary>
        private void RestoreNative()
        {
            if (_native != null)
            {
                _native.Destroy();
            }

            _native = new NativeAnimation();
            _native.OnEventTriggered += EventTriggered;

            animatedRenderable = SceneObject.GetComponent <Renderable>();

            // Restore saved values after reset
            _native.WrapMode = serializableData.wrapMode;
            _native.Speed    = serializableData.speed;
            _native.Cull     = serializableData.cull;

            UpdateBounds();

            if (serializableData.defaultClip != null)
            {
                _native.Play(serializableData.defaultClip);
            }

            primaryClip = _native.GetClip(0);
            if (primaryClip != null)
            {
                RebuildFloatProperties(primaryClip);
            }

            SetBoneMappings();
            UpdateSceneObjectMapping();

            if (animatedRenderable != null)
            {
                animatedRenderable.RegisterAnimation(this);
            }
        }