/**
         * <summary>Deserialises a string of data, and restores the GameObject to it's previous state.</summary>
         * <param name = "stringData">The data, serialised as a string</param>
         */
        public void LoadTransformData(TransformData data)
        {
            if (data == null) return;

            if (data.parentIsPlayer)
            {
                if (KickStarter.player)
                {
                    if (data.heldHand == Hand.Left)
                    {
                        transform.parent = KickStarter.player.leftHandBone;
                    }
                    else
                    {
                        transform.parent = KickStarter.player.rightHandBone;
                    }
                }
            }
            else if (data.parentID != 0)
            {
                ConstantID parentObject = Serializer.returnComponent <ConstantID> (data.parentID);

                if (parentObject != null)
                {
                    if (data.parentIsNPC && parentObject.GetComponent <NPC>())
                    {
                        if (data.heldHand == Hand.Left)
                        {
                            transform.parent = parentObject.GetComponent <NPC>().leftHandBone;
                        }
                        else
                        {
                            transform.parent = parentObject.GetComponent <NPC>().rightHandBone;
                        }
                    }
                    else
                    {
                        transform.parent = parentObject.gameObject.transform;
                    }
                }
            }
            else if (data.parentID == 0 && saveParent)
            {
                transform.parent = null;
            }

            transform.position = new Vector3 (data.LocX, data.LocY, data.LocZ);
            transform.eulerAngles = new Vector3 (data.RotX, data.RotY, data.RotZ);
            transform.localScale = new Vector3 (data.ScaleX, data.ScaleY, data.ScaleZ);
        }
        /**
         * <summary>Serialises appropriate GameObject values into a string.</summary>
         * <returns>The data, serialised as a string</returns>
         */
        public TransformData SaveTransformData()
        {
            TransformData transformData = new TransformData();

            transformData.objectID = constantID;

            transformData.LocX = transform.position.x;
            transformData.LocY = transform.position.y;
            transformData.LocZ = transform.position.z;

            transformData.RotX = transform.eulerAngles.x;
            transformData.RotY = transform.eulerAngles.y;
            transformData.RotZ = transform.eulerAngles.z;

            transformData.ScaleX = transform.localScale.x;
            transformData.ScaleY = transform.localScale.y;
            transformData.ScaleZ = transform.localScale.z;

            transformData.bringBack = saveScenePresence;

            if (saveParent)
            {
                // Attempt to find the "hand" bone of a character
                Transform t = transform.parent;

                if (t == null)
                {
                    transformData.parentID = 0;
                    return transformData;
                }

                while (t.parent != null)
                {
                    t = t.parent;

                    if (t.GetComponent <AC.Char>())
                    {
                        AC.Char parentCharacter = t.GetComponent <AC.Char>();

                        if (parentCharacter is Player || (parentCharacter.GetComponent <ConstantID>() && parentCharacter.GetComponent <ConstantID>().constantID != 0))
                        {
                            if (transform.parent == parentCharacter.leftHandBone || transform.parent == parentCharacter.rightHandBone)
                            {
                                if (parentCharacter is Player)
                                {
                                    transformData.parentIsPlayer = true;
                                    transformData.parentIsNPC = false;
                                    transformData.parentID = 0;
                                }
                                else
                                {
                                    transformData.parentIsPlayer = false;
                                    transformData.parentIsNPC = true;
                                    transformData.parentID = parentCharacter.GetComponent <ConstantID>().constantID;
                                }

                                if (transform.parent == parentCharacter.leftHandBone)
                                {
                                    transformData.heldHand = Hand.Left;
                                }
                                else
                                {
                                    transformData.heldHand = Hand.Right;
                                }

                                return transformData;
                            }
                        }

                        break;
                    }
                }

                if (transform.parent.GetComponent <ConstantID>() && transform.parent.GetComponent <ConstantID>().constantID != 0)
                {
                    transformData.parentID = transform.parent.GetComponent <ConstantID>().constantID;
                }
                else
                {
                    transformData.parentID = 0;
                    ACDebug.LogWarning ("Could not save " + this.name + "'s parent since it has no Constant ID");
                }
            }

            return transformData;
        }
Esempio n. 3
0
        /**
         * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary>
         * <param name = "stringData">The data, serialised as a string</param>
         */
        public void LoadTransformData(TransformData data)
        {
            if (data == null)
            {
                return;
            }
            savePrevented = data.savePrevented; if (savePrevented)
            {
                return;
            }

            if (data.parentIsPlayer)
            {
                if (KickStarter.player)
                {
                    if (data.heldHand == Hand.Left)
                    {
                        transform.parent = KickStarter.player.leftHandBone;
                    }
                    else
                    {
                        transform.parent = KickStarter.player.rightHandBone;
                    }
                }
            }
            else if (data.parentID != 0)
            {
                ConstantID parentObject = Serializer.returnComponent <ConstantID> (data.parentID);

                if (parentObject != null)
                {
                    if (data.parentIsNPC && parentObject.GetComponent <NPC>())
                    {
                        if (data.heldHand == Hand.Left)
                        {
                            transform.parent = parentObject.GetComponent <NPC>().leftHandBone;
                        }
                        else
                        {
                            transform.parent = parentObject.GetComponent <NPC>().rightHandBone;
                        }
                    }
                    else
                    {
                        transform.parent = parentObject.gameObject.transform;
                    }
                }
            }
            else if (data.parentID == 0 && saveParent)
            {
                transform.parent = null;
            }

            switch (transformSpace)
            {
            case GlobalLocal.Global:
                transform.position    = new Vector3(data.LocX, data.LocY, data.LocZ);
                transform.eulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ);
                break;

            case GlobalLocal.Local:
                transform.localPosition    = new Vector3(data.LocX, data.LocY, data.LocZ);
                transform.localEulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ);
                break;
            }

            transform.localScale = new Vector3(data.ScaleX, data.ScaleY, data.ScaleZ);
        }
Esempio n. 4
0
        /**
         * <summary>Serialises appropriate GameObject values into a string.</summary>
         * <returns>The data, serialised as a string</returns>
         */
        public TransformData SaveTransformData()
        {
            TransformData transformData = new TransformData();

            transformData.objectID      = constantID;
            transformData.savePrevented = savePrevented;

            switch (transformSpace)
            {
            case GlobalLocal.Global:
            {
                transformData.LocX = transform.position.x;
                transformData.LocY = transform.position.y;
                transformData.LocZ = transform.position.z;

                Char attachedChar = transform.GetComponent <Char> ();
                if (attachedChar != null)
                {
                    transformData.RotX = attachedChar.TransformRotation.eulerAngles.x;
                    transformData.RotY = attachedChar.TransformRotation.eulerAngles.y;
                    transformData.RotZ = attachedChar.TransformRotation.eulerAngles.z;
                }
                else
                {
                    transformData.RotX = transform.eulerAngles.x;
                    transformData.RotY = transform.eulerAngles.y;
                    transformData.RotZ = transform.eulerAngles.z;
                }
            }
            break;

            case GlobalLocal.Local:
            {
                transformData.LocX = transform.localPosition.x;
                transformData.LocY = transform.localPosition.y;
                transformData.LocZ = transform.localPosition.z;

                transformData.RotX = transform.localEulerAngles.x;
                transformData.RotY = transform.localEulerAngles.y;
                transformData.RotZ = transform.localEulerAngles.z;
            }
            break;
            }

            transformData.ScaleX = transform.localScale.x;
            transformData.ScaleY = transform.localScale.y;
            transformData.ScaleZ = transform.localScale.z;

            transformData.bringBack      = saveScenePresence;
            transformData.linkedPrefabID = (saveScenePresence) ? linkedPrefabID : 0;

            if (saveParent)
            {
                // Attempt to find the "hand" bone of a character
                Transform t = transform.parent;

                if (t == null)
                {
                    transformData.parentID = 0;
                    return(transformData);
                }

                while (t.parent != null)
                {
                    t = t.parent;

                    AC.Char parentCharacter = t.GetComponent <AC.Char>();
                    if (parentCharacter != null)
                    {
                        if (parentCharacter is Player || (parentCharacter.GetComponent <ConstantID>() && parentCharacter.GetComponent <ConstantID>().constantID != 0))
                        {
                            if (transform.parent == parentCharacter.leftHandBone || transform.parent == parentCharacter.rightHandBone)
                            {
                                if (parentCharacter.IsPlayer)
                                {
                                    transformData.parentIsPlayer = true;
                                    transformData.parentIsNPC    = false;
                                    transformData.parentID       = 0;
                                }
                                else
                                {
                                    transformData.parentIsPlayer = false;
                                    transformData.parentIsNPC    = true;
                                    transformData.parentID       = parentCharacter.GetComponent <ConstantID>().constantID;
                                }

                                if (transform.parent == parentCharacter.leftHandBone)
                                {
                                    transformData.heldHand = Hand.Left;
                                }
                                else
                                {
                                    transformData.heldHand = Hand.Right;
                                }

                                return(transformData);
                            }
                        }

                        break;
                    }
                }

                if (transform.parent.GetComponent <ConstantID>() && transform.parent.GetComponent <ConstantID>().constantID != 0)
                {
                    transformData.parentID = transform.parent.GetComponent <ConstantID>().constantID;
                }
                else
                {
                    transformData.parentID = 0;
                    ACDebug.LogWarning("Could not save " + this.name + "'s parent since it has no Constant ID", this);
                }
            }

            return(transformData);
        }
Esempio n. 5
0
        public TransformData SaveTransformData()
        {
            TransformData transformData = new TransformData();

            transformData.objectID = constantID;

            transformData.LocX = transform.position.x;
            transformData.LocY = transform.position.y;
            transformData.LocZ = transform.position.z;

            transformData.RotX = transform.eulerAngles.x;
            transformData.RotY = transform.eulerAngles.y;
            transformData.RotZ = transform.eulerAngles.z;

            transformData.ScaleX = transform.localScale.x;
            transformData.ScaleY = transform.localScale.y;
            transformData.ScaleZ = transform.localScale.z;

            transformData.bringBack = saveScenePresence;

            if (saveParent)
            {
                // Attempt to find the "hand" bone of a character
                Transform t = transform.parent;

                if (t == null)
                {
                    transformData.parentID = 0;
                    return(transformData);
                }

                while (t.parent != null)
                {
                    t = t.parent;

                    if (t.GetComponent <AC.Char>())
                    {
                        AC.Char parentCharacter = t.GetComponent <AC.Char>();

                        if (parentCharacter is Player || (parentCharacter.GetComponent <ConstantID>() && parentCharacter.GetComponent <ConstantID>().constantID != 0))
                        {
                            if (transform.parent == parentCharacter.leftHandBone || transform.parent == parentCharacter.rightHandBone)
                            {
                                if (parentCharacter is Player)
                                {
                                    transformData.parentIsPlayer = true;
                                    transformData.parentIsNPC    = false;
                                    transformData.parentID       = 0;
                                }
                                else
                                {
                                    transformData.parentIsPlayer = false;
                                    transformData.parentIsNPC    = true;
                                    transformData.parentID       = parentCharacter.GetComponent <ConstantID>().constantID;
                                }

                                if (transform.parent == parentCharacter.leftHandBone)
                                {
                                    transformData.heldHand = ActionCharHold.Hand.Left;
                                }
                                else
                                {
                                    transformData.heldHand = ActionCharHold.Hand.Right;
                                }

                                return(transformData);
                            }
                        }

                        break;
                    }
                }

                if (transform.parent.GetComponent <ConstantID>() && transform.parent.GetComponent <ConstantID>().constantID != 0)
                {
                    transformData.parentID = transform.parent.GetComponent <ConstantID>().constantID;
                }
                else
                {
                    transformData.parentID = 0;
                    Debug.LogWarning("Could not save " + this.name + "'s parent since it has no Constant ID");
                }
            }

            return(transformData);
        }