Esempio n. 1
0
 /**
  * <summary>Unregisters a FollowSortingMap, so that it is no longer updated</summary>
  * <param name = "_object">The FollowSortingMap to unregister</param>
  */
 public void Unregister(FollowSortingMap _object)
 {
     if (followSortingMaps.Contains(_object))
     {
         followSortingMaps.Remove(_object);
     }
 }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            FollowSortingMap _target = (FollowSortingMap)target;

            _target.followSortingMap = CustomGUILayout.Toggle("Follow default Sorting Map?", _target.followSortingMap, "", "If True, then the component will follow the default Sorting Map defined in the Scene Manager");
            if (!_target.followSortingMap)
            {
                _target.customSortingMap = (SortingMap)CustomGUILayout.ObjectField <SortingMap> ("Sorting Map to follow:", _target.customSortingMap, true, "", "The Sorting Map to follow");
            }

            if (_target.followSortingMap || _target.customSortingMap != null)
            {
                _target.offsetOriginal = CustomGUILayout.Toggle("Offset original Order?", _target.offsetOriginal, "", "If True, then the SpriteRenderer's sorting values will be increased by their original values when the game began");
                _target.affectChildren = CustomGUILayout.Toggle("Also affect children?", _target.affectChildren, "", "If True, then the sorting values of child SpriteRenderers will be affected as well");

                bool oldPreviewValue = _target.livePreview;
                _target.livePreview = CustomGUILayout.Toggle("Edit-mode preview?", _target.livePreview, "", "If True, then the script will update the SpriteRender's sorting values when the game is not running");
                if (oldPreviewValue && !_target.livePreview)
                {
                    // Just unchecked, so reset scale
                    if (!Application.isPlaying && _target.GetComponentInParent <Char>() != null && _target.GetComponentInParent <Char>().spriteChild != null)
                    {
                        _target.GetComponentInParent <Char>().transform.localScale = Vector3.one;
                    }
                }
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            FollowSortingMap _target = (FollowSortingMap)target;

            _target.followSortingMap = EditorGUILayout.Toggle("Follow default Sorting Map?", _target.followSortingMap);
            if (!_target.followSortingMap)
            {
                _target.customSortingMap = (SortingMap)EditorGUILayout.ObjectField("Sorting Map to follow:", _target.customSortingMap, typeof(SortingMap), true);
            }

            if (_target.followSortingMap || _target.customSortingMap != null)
            {
                _target.offsetOriginal = EditorGUILayout.Toggle("Offset original Order?", _target.offsetOriginal);
                _target.affectChildren = EditorGUILayout.Toggle("Also affect children?", _target.affectChildren);

                bool oldPreviewValue = _target.livePreview;
                _target.livePreview = EditorGUILayout.Toggle("Edit-mode preview?", _target.livePreview);
                if (oldPreviewValue && !_target.livePreview)
                {
                    // Just unchecked, so reset scale
                    if (!Application.isPlaying && _target.GetComponentInParent <Char>() != null && _target.GetComponentInParent <Char>().spriteChild != null)
                    {
                        _target.GetComponentInParent <Char>().transform.localScale = Vector3.one;
                    }
                }
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
Esempio n. 4
0
 /**
  * <summary>Registers a FollowSortingMap, so that it can be updated</summary>
  * <param name = "_object">The FollowSortingMap to register</param>
  */
 public void Register(FollowSortingMap _object)
 {
     if (!followSortingMaps.Contains(_object))
     {
         followSortingMaps.Add(_object);
         _object.UpdateSortingMap();
     }
 }
        public override void OnInspectorGUI()
        {
            FollowSortingMap _target = (FollowSortingMap)target;

            _target.followSortingMap = EditorGUILayout.Toggle("Follow Sorting map?", _target.followSortingMap);

            if (_target.followSortingMap)
            {
                _target.offsetOriginal = EditorGUILayout.Toggle("Offset original Order?", _target.offsetOriginal);
                _target.affectChildren = EditorGUILayout.Toggle("Also affect children?", _target.affectChildren);
                _target.livePreview    = EditorGUILayout.Toggle("Edit-mode preview?", _target.livePreview);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }
        public override void OnInspectorGUI()
        {
            FollowSortingMap _target = (FollowSortingMap)target;

            _target.followSortingMap = EditorGUILayout.Toggle("Follow default Sorting Map?", _target.followSortingMap);
            if (!_target.followSortingMap)
            {
                _target.customSortingMap = (SortingMap)EditorGUILayout.ObjectField("Sorting Map to follow:", _target.customSortingMap, typeof(SortingMap), true);
            }

            if (_target.followSortingMap || _target.customSortingMap != null)
            {
                _target.offsetOriginal = EditorGUILayout.Toggle("Offset original Order?", _target.offsetOriginal);
                _target.affectChildren = EditorGUILayout.Toggle("Also affect children?", _target.affectChildren);
                _target.livePreview    = EditorGUILayout.Toggle("Edit-mode preview?", _target.livePreview);
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
Esempio n. 7
0
        public void UpdateSimilarFollowers(FollowSortingMap follower)
        {
            if (followers == null || followers.Length <= 1)
            {
                return;
            }

            if (follower.followSortingMap)
            {
                string testOrder = follower.GetOrder();
                List <FollowSortingMap> testFollowers = new List <FollowSortingMap>();

                foreach (FollowSortingMap testFollower in followers)
                {
                    if (testFollower.followSortingMap && !testFollower.lockSorting && testFollower != follower && testFollower.GetOrder() == testOrder)
                    {
                        // Found a follower with the same order/layer
                        testFollowers.Add(testFollower);
                    }
                }

                if (testFollowers.Count > 0)
                {
                    testFollowers.Add(follower);
                    if (testFollowers.Count > 1)
                    {
                        testFollowers.Sort(SortByScreenPosition);
                    }
                    // Now in order from bottom up

                    for (int i = 0; i < testFollowers.Count; i++)
                    {
                        testFollowers [i].SetDepth(i * 0.001f);
                    }
                }
                else
                {
                    follower.SetDepth(0f);
                }
            }
        }
Esempio n. 8
0
		public void UpdateSimilarFollowers (FollowSortingMap follower)
		{
			if (followers == null || followers.Length <= 1)
			{
				return;
			}
			
			if (follower.followSortingMap)
			{
				string testOrder = follower.GetOrder ();
				List<FollowSortingMap> testFollowers = new List<FollowSortingMap>();
				
				foreach (FollowSortingMap testFollower in followers)
				{
					if (testFollower.followSortingMap && !testFollower.lockSorting && testFollower != follower && testFollower.GetOrder () == testOrder)
					{
						// Found a follower with the same order/layer
						testFollowers.Add (testFollower);
					}
				}
				
				if (testFollowers.Count > 0)
				{
					testFollowers.Add (follower);
					testFollowers.Sort (SortByScreenPosition);
					// Now in order from bottom up
					
					for (int i=0; i<testFollowers.Count; i++)
					{
						testFollowers [i].SetDepth (i * 0.001f);
					}
				}
				else
				{
					follower.SetDepth (0f);
				}
			}
		}
Esempio n. 9
0
 private static int SortByScreenPosition(FollowSortingMap o1, FollowSortingMap o2)
 {
     return(Camera.main.WorldToScreenPoint(o1.transform.position).y.CompareTo(Camera.main.WorldToScreenPoint(o2.transform.position).y));
 }
Esempio n. 10
0
 /**
  * <summary>Unregisters a FollowSortingMap, so that it is no longer updated</summary>
  * <param name = "_object">The FollowSortingMap to unregister</param>
  */
 public void Unregister(FollowSortingMap _object)
 {
     followSortingMaps.Remove(_object);
 }
Esempio n. 11
0
 /**
  * <summary>Registers a FollowSortingMap, so that it can be updated</summary>
  * <param name = "_object">The FollowSortingMap to register</param>
  */
 public void Register(FollowSortingMap _object)
 {
     followSortingMaps.Add(_object);
     _object.UpdateSortingMap();
 }
Esempio n. 12
0
 private static int SortByScreenPosition(FollowSortingMap o1, FollowSortingMap o2)
 {
     return Camera.main.WorldToScreenPoint (o1.transform.position).y.CompareTo (Camera.main.WorldToScreenPoint (o2.transform.position).y);
 }
Esempio n. 13
0
        /**
         * <summary>Updates a NPCData class with its own variables that need saving.</summary>
         * <param name = "npcData">The original NPCData class</param>
         * <returns>The updated NPCData class</returns>
         */
        public NPCData SaveData(NPCData npcData)
        {
            npcData.RotX = TransformRotation.eulerAngles.x;
            npcData.RotY = TransformRotation.eulerAngles.y;
            npcData.RotZ = TransformRotation.eulerAngles.z;

            npcData.inCustomCharState = (charState == CharState.Custom && GetAnimator() != null && GetAnimator().GetComponent <RememberAnimator>());

            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity)
            {
                npcData.idleAnim = idleAnimSprite;
                npcData.walkAnim = walkAnimSprite;
                npcData.talkAnim = talkAnimSprite;
                npcData.runAnim  = runAnimSprite;
            }
            else if (animationEngine == AnimationEngine.Legacy)
            {
                npcData.idleAnim = AssetLoader.GetAssetInstanceID(idleAnim);
                npcData.walkAnim = AssetLoader.GetAssetInstanceID(walkAnim);
                npcData.runAnim  = AssetLoader.GetAssetInstanceID(runAnim);
                npcData.talkAnim = AssetLoader.GetAssetInstanceID(talkAnim);
            }
            else if (animationEngine == AnimationEngine.Mecanim)
            {
                npcData.walkAnim = moveSpeedParameter;
                npcData.talkAnim = talkParameter;
                npcData.runAnim  = turnParameter;
            }

            npcData.walkSound = AssetLoader.GetAssetInstanceID(walkSound);
            npcData.runSound  = AssetLoader.GetAssetInstanceID(runSound);

            npcData.speechLabel     = GetName();
            npcData.displayLineID   = displayLineID;
            npcData.portraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture);

            npcData.walkSpeed = walkSpeedScale;
            npcData.runSpeed  = runSpeedScale;

            // Rendering
            npcData.lockDirection = lockDirection;
            npcData.lockScale     = lockScale;
            if (spriteChild && spriteChild.GetComponent <FollowSortingMap>())
            {
                npcData.lockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting;
            }
            else if (GetComponent <FollowSortingMap>())
            {
                npcData.lockSorting = GetComponent <FollowSortingMap>().lockSorting;
            }
            else
            {
                npcData.lockSorting = false;
            }
            npcData.spriteDirection = spriteDirection;
            npcData.spriteScale     = spriteScale;
            if (spriteChild && spriteChild.GetComponent <Renderer>())
            {
                npcData.sortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder;
                npcData.sortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName;
            }
            else if (GetComponent <Renderer>())
            {
                npcData.sortingOrder = GetComponent <Renderer>().sortingOrder;
                npcData.sortingLayer = GetComponent <Renderer>().sortingLayerName;
            }

            npcData.pathID     = 0;
            npcData.lastPathID = 0;
            if (GetPath())
            {
                npcData.targetNode  = GetTargetNode();
                npcData.prevNode    = GetPreviousNode();
                npcData.isRunning   = isRunning;
                npcData.pathAffectY = GetPath().affectY;

                if (GetPath() == GetComponent <Paths>())
                {
                    npcData.pathData = Serializer.CreatePathData(GetComponent <Paths>());
                }
                else
                {
                    if (GetPath().GetComponent <ConstantID>())
                    {
                        npcData.pathID = GetPath().GetComponent <ConstantID>().constantID;
                    }
                    else
                    {
                        ACDebug.LogWarning("Want to save path data for " + name + " but path has no ID!", gameObject);
                    }
                }
            }

            if (GetLastPath())
            {
                npcData.lastTargetNode = GetLastTargetNode();
                npcData.lastPrevNode   = GetLastPrevNode();

                if (GetLastPath().GetComponent <ConstantID>())
                {
                    npcData.lastPathID = GetLastPath().GetComponent <ConstantID>().constantID;
                }
                else
                {
                    ACDebug.LogWarning("Want to save previous path data for " + name + " but path has no ID!", gameObject);
                }
            }

            if (followTarget)
            {
                if (!followTargetIsPlayer)
                {
                    if (followTarget.GetComponent <ConstantID>())
                    {
                        npcData.followTargetID        = followTarget.GetComponent <ConstantID>().constantID;
                        npcData.followTargetIsPlayer  = followTargetIsPlayer;
                        npcData.followFrequency       = followFrequency;
                        npcData.followDistance        = followDistance;
                        npcData.followDistanceMax     = followDistanceMax;
                        npcData.followFaceWhenIdle    = followFaceWhenIdle;
                        npcData.followRandomDirection = followRandomDirection;
                    }
                    else
                    {
                        ACDebug.LogWarning("Want to save follow data for " + name + " but " + followTarget.name + " has no ID!", gameObject);
                    }
                }
                else
                {
                    npcData.followTargetID       = 0;
                    npcData.followTargetIsPlayer = followTargetIsPlayer;
                    npcData.followFrequency      = followFrequency;
                    npcData.followDistance       = followDistance;
                    npcData.followDistanceMax    = followDistanceMax;
                    //followFaceWhenIdle = false;
                    npcData.followFaceWhenIdle    = followFaceWhenIdle;
                    npcData.followRandomDirection = followRandomDirection;
                }
            }
            else
            {
                npcData.followTargetID        = 0;
                npcData.followTargetIsPlayer  = false;
                npcData.followFrequency       = 0f;
                npcData.followDistance        = 0f;
                npcData.followDistanceMax     = 0f;
                npcData.followFaceWhenIdle    = false;
                npcData.followRandomDirection = false;
            }

            if (headFacing == HeadFacing.Manual && headTurnTarget != null)
            {
                npcData.isHeadTurning = true;
                npcData.headTargetID  = Serializer.GetConstantID(headTurnTarget);
                if (npcData.headTargetID == 0)
                {
                    ACDebug.LogWarning("The NPC " + gameObject.name + "'s head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject);
                }
                npcData.headTargetX = headTurnTargetOffset.x;
                npcData.headTargetY = headTurnTargetOffset.y;
                npcData.headTargetZ = headTurnTargetOffset.z;
            }
            else
            {
                npcData.isHeadTurning = false;
                npcData.headTargetID  = 0;
                npcData.headTargetX   = 0f;
                npcData.headTargetY   = 0f;
                npcData.headTargetZ   = 0f;
            }

            if (GetComponentInChildren <FollowSortingMap>() != null)
            {
                FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>();
                npcData.followSortingMap = followSortingMap.followSortingMap;
                if (!npcData.followSortingMap && followSortingMap.GetSortingMap() != null)
                {
                    if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null)
                    {
                        npcData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID;
                    }
                    else
                    {
                        ACDebug.LogWarning("The NPC " + gameObject.name + "'s SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID");
                        npcData.customSortingMapID = 0;
                    }
                }
                else
                {
                    npcData.customSortingMapID = 0;
                }
            }
            else
            {
                npcData.followSortingMap   = false;
                npcData.customSortingMapID = 0;
            }

            return(npcData);
        }
Esempio n. 14
0
        /**
         * <summary>Updates a PlayerData class with its own variables that need saving.</summary>
         * <param name = "playerData">The original PlayerData class</param>
         * <returns>The updated PlayerData class</returns>
         */
        public PlayerData SaveData(PlayerData playerData)
        {
            playerData.playerID = ID;

            playerData.playerLocX = transform.position.x;
            playerData.playerLocY = transform.position.y;
            playerData.playerLocZ = transform.position.z;
            playerData.playerRotY = TransformRotation.eulerAngles.y;

            playerData.inCustomCharState = (charState == CharState.Custom && GetAnimator() != null && GetAnimator().GetComponent <RememberAnimator>());

            playerData.playerWalkSpeed = walkSpeedScale;
            playerData.playerRunSpeed  = runSpeedScale;

            playerData.playerUpLock      = upMovementLocked;
            playerData.playerDownLock    = downMovementLocked;
            playerData.playerLeftlock    = leftMovementLocked;
            playerData.playerRightLock   = rightMovementLocked;
            playerData.playerRunLock     = (int)runningLocked;
            playerData.playerFreeAimLock = freeAimLocked;

            // Animation clips
            playerData = GetAnimEngine().SavePlayerData(playerData, this);

            // Sound
            playerData.playerWalkSound = AssetLoader.GetAssetInstanceID(walkSound);
            playerData.playerRunSound  = AssetLoader.GetAssetInstanceID(runSound);

            // Portrait graphic
            playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture);

            // Speech label
            playerData.playerSpeechLabel   = GetName();
            playerData.playerDisplayLineID = displayLineID;

            // Rendering
            playerData.playerLockDirection = lockDirection;
            playerData.playerLockScale     = lockScale;
            if (spriteChild && spriteChild.GetComponent <FollowSortingMap>())
            {
                playerData.playerLockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting;
            }
            else if (GetComponent <FollowSortingMap>())
            {
                playerData.playerLockSorting = GetComponent <FollowSortingMap>().lockSorting;
            }
            else
            {
                playerData.playerLockSorting = false;
            }

            playerData.playerSpriteDirection = GetSpriteDirectionToSave();

            playerData.playerSpriteScale = spriteScale;
            if (spriteChild && spriteChild.GetComponent <Renderer>())
            {
                playerData.playerSortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder;
                playerData.playerSortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName;
            }
            else if (GetComponent <Renderer>())
            {
                playerData.playerSortingOrder = GetComponent <Renderer>().sortingOrder;
                playerData.playerSortingLayer = GetComponent <Renderer>().sortingLayerName;
            }

            playerData.playerActivePath     = 0;
            playerData.lastPlayerActivePath = 0;
            if (GetPath())
            {
                playerData.playerTargetNode  = GetTargetNode();
                playerData.playerPrevNode    = GetPreviousNode();
                playerData.playerIsRunning   = isRunning;
                playerData.playerPathAffectY = activePath.affectY;

                if (GetComponent <Paths>() && GetPath() == GetComponent <Paths>())
                {
                    playerData.playerPathData   = Serializer.CreatePathData(GetComponent <Paths>());
                    playerData.playerLockedPath = false;
                }
                else
                {
                    playerData.playerPathData   = string.Empty;
                    playerData.playerActivePath = Serializer.GetConstantID(GetPath().gameObject);
                    playerData.playerLockedPath = lockedPath;
                }
            }

            if (GetLastPath())
            {
                playerData.lastPlayerTargetNode = GetLastTargetNode();
                playerData.lastPlayerPrevNode   = GetLastPrevNode();
                playerData.lastPlayerActivePath = Serializer.GetConstantID(GetLastPath().gameObject);
            }

            playerData.playerIgnoreGravity = ignoreGravity;

            // Head target
            playerData.playerLockHotspotHeadTurning = lockHotspotHeadTurning;
            if (headFacing == HeadFacing.Manual && headTurnTarget != null)
            {
                playerData.isHeadTurning = true;
                playerData.headTargetID  = Serializer.GetConstantID(headTurnTarget);
                if (playerData.headTargetID == 0)
                {
                    ACDebug.LogWarning("The Player's head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject);
                }
                playerData.headTargetX = headTurnTargetOffset.x;
                playerData.headTargetY = headTurnTargetOffset.y;
                playerData.headTargetZ = headTurnTargetOffset.z;
            }
            else
            {
                playerData.isHeadTurning = false;
                playerData.headTargetID  = 0;
                playerData.headTargetX   = 0f;
                playerData.headTargetY   = 0f;
                playerData.headTargetZ   = 0f;
            }

            FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>();

            if (followSortingMap != null)
            {
                playerData.followSortingMap = followSortingMap.followSortingMap;
                if (!playerData.followSortingMap && followSortingMap.GetSortingMap() != null)
                {
                    if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null)
                    {
                        playerData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID;
                    }
                    else
                    {
                        ACDebug.LogWarning("The Player's SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID", gameObject);
                        playerData.customSortingMapID = 0;
                    }
                }
                else
                {
                    playerData.customSortingMapID = 0;
                }
            }
            else
            {
                playerData.followSortingMap   = false;
                playerData.customSortingMapID = 0;
            }

            // Inactive Player follow
            if (followTarget != null && !IsActivePlayer())
            {
                if (!followTargetIsPlayer)
                {
                    if (followTarget.GetComponent <ConstantID> ())
                    {
                        playerData.followTargetID        = followTarget.GetComponent <ConstantID> ().constantID;
                        playerData.followTargetIsPlayer  = followTargetIsPlayer;
                        playerData.followFrequency       = followFrequency;
                        playerData.followDistance        = followDistance;
                        playerData.followDistanceMax     = followDistanceMax;
                        playerData.followFaceWhenIdle    = followFaceWhenIdle;
                        playerData.followRandomDirection = followRandomDirection;
                    }
                    else
                    {
                        ACDebug.LogWarning("Want to save follow data for " + name + " but " + followTarget.name + " has no ID!", gameObject);
                    }
                }
                else
                {
                    playerData.followTargetID        = 0;
                    playerData.followTargetIsPlayer  = followTargetIsPlayer;
                    playerData.followFrequency       = followFrequency;
                    playerData.followDistance        = followDistance;
                    playerData.followDistanceMax     = followDistanceMax;
                    playerData.followFaceWhenIdle    = followFaceWhenIdle;
                    playerData.followRandomDirection = followRandomDirection;
                }
            }
            else
            {
                playerData.followTargetID        = 0;
                playerData.followTargetIsPlayer  = false;
                playerData.followFrequency       = 0f;
                playerData.followDistance        = 0f;
                playerData.followDistanceMax     = 0f;
                playerData.followFaceWhenIdle    = false;
                playerData.followRandomDirection = false;
            }

            playerData.leftHandIKState  = LeftHandIKController.CreateSaveData();
            playerData.rightHandIKState = RightHandIKController.CreateSaveData();

            playerData.spriteDirectionData = spriteDirectionData.SaveData();

            // Remember scripts
            if (!IsLocalPlayer() && gameObject.activeInHierarchy)
            {
                playerData = KickStarter.levelStorage.SavePlayerData(this, playerData);
            }

            return(playerData);
        }
Esempio n. 15
0
        /**
         * <summary>Updates a PlayerData class with its own variables that need saving.</summary>
         * <param name = "playerData">The original PlayerData class</param>
         * <returns>The updated PlayerData class</returns>
         */
        public PlayerData SavePlayerData(PlayerData playerData)
        {
            playerData.playerID = ID;

            playerData.playerLocX = transform.position.x;
            playerData.playerLocY = transform.position.y;
            playerData.playerLocZ = transform.position.z;
            playerData.playerRotY = TransformRotation.eulerAngles.y;

            playerData.playerWalkSpeed = walkSpeedScale;
            playerData.playerRunSpeed  = runSpeedScale;

            // Animation clips
            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity)
            {
                playerData.playerIdleAnim = idleAnimSprite;
                playerData.playerWalkAnim = walkAnimSprite;
                playerData.playerRunAnim  = runAnimSprite;
                playerData.playerTalkAnim = talkAnimSprite;
            }
            else if (animationEngine == AnimationEngine.Legacy)
            {
                playerData.playerIdleAnim = AssetLoader.GetAssetInstanceID(idleAnim);
                playerData.playerWalkAnim = AssetLoader.GetAssetInstanceID(walkAnim);
                playerData.playerRunAnim  = AssetLoader.GetAssetInstanceID(runAnim);
                playerData.playerTalkAnim = AssetLoader.GetAssetInstanceID(talkAnim);
            }
            else if (animationEngine == AnimationEngine.Mecanim)
            {
                playerData.playerWalkAnim = moveSpeedParameter;
                playerData.playerTalkAnim = talkParameter;
                playerData.playerRunAnim  = turnParameter;
            }

            // Sound
            playerData.playerWalkSound = AssetLoader.GetAssetInstanceID(walkSound);
            playerData.playerRunSound  = AssetLoader.GetAssetInstanceID(runSound);

            // Portrait graphic
            playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture);

            // Speech label
            playerData.playerSpeechLabel   = GetName();
            playerData.playerDisplayLineID = displayLineID;

            // Rendering
            playerData.playerLockDirection = lockDirection;
            playerData.playerLockScale     = lockScale;
            if (spriteChild && spriteChild.GetComponent <FollowSortingMap>())
            {
                playerData.playerLockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting;
            }
            else if (GetComponent <FollowSortingMap>())
            {
                playerData.playerLockSorting = GetComponent <FollowSortingMap>().lockSorting;
            }
            else
            {
                playerData.playerLockSorting = false;
            }
            playerData.playerSpriteDirection = spriteDirection;
            playerData.playerSpriteScale     = spriteScale;
            if (spriteChild && spriteChild.GetComponent <Renderer>())
            {
                playerData.playerSortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder;
                playerData.playerSortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName;
            }
            else if (GetComponent <Renderer>())
            {
                playerData.playerSortingOrder = GetComponent <Renderer>().sortingOrder;
                playerData.playerSortingLayer = GetComponent <Renderer>().sortingLayerName;
            }

            playerData.playerActivePath     = 0;
            playerData.lastPlayerActivePath = 0;
            if (GetPath())
            {
                playerData.playerTargetNode  = GetTargetNode();
                playerData.playerPrevNode    = GetPrevNode();
                playerData.playerIsRunning   = isRunning;
                playerData.playerPathAffectY = activePath.affectY;

                if (GetComponent <Paths>() && GetPath() == GetComponent <Paths>())
                {
                    playerData.playerPathData   = Serializer.CreatePathData(GetComponent <Paths>());
                    playerData.playerLockedPath = false;
                }
                else
                {
                    playerData.playerPathData   = "";
                    playerData.playerActivePath = Serializer.GetConstantID(GetPath().gameObject);
                    playerData.playerLockedPath = lockedPath;
                }
            }

            if (GetLastPath())
            {
                playerData.lastPlayerTargetNode = GetLastTargetNode();
                playerData.lastPlayerPrevNode   = GetLastPrevNode();
                playerData.lastPlayerActivePath = Serializer.GetConstantID(GetLastPath().gameObject);
            }

            playerData.playerIgnoreGravity = ignoreGravity;

            // Head target
            playerData.playerLockHotspotHeadTurning = lockHotspotHeadTurning;
            if (headFacing == HeadFacing.Manual && headTurnTarget != null)
            {
                playerData.isHeadTurning = true;
                playerData.headTargetID  = Serializer.GetConstantID(headTurnTarget);
                if (playerData.headTargetID == 0)
                {
                    ACDebug.LogWarning("The Player's head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID");
                }
                playerData.headTargetX = headTurnTargetOffset.x;
                playerData.headTargetY = headTurnTargetOffset.y;
                playerData.headTargetZ = headTurnTargetOffset.z;
            }
            else
            {
                playerData.isHeadTurning = false;
                playerData.headTargetID  = 0;
                playerData.headTargetX   = 0f;
                playerData.headTargetY   = 0f;
                playerData.headTargetZ   = 0f;
            }

            if (GetComponentInChildren <FollowSortingMap>() != null)
            {
                FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>();
                playerData.followSortingMap = followSortingMap.followSortingMap;
                if (!playerData.followSortingMap && followSortingMap.GetSortingMap() != null)
                {
                    if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null)
                    {
                        playerData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID;
                    }
                    else
                    {
                        ACDebug.LogWarning("The Player's SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID");
                        playerData.customSortingMapID = 0;
                    }
                }
                else
                {
                    playerData.customSortingMapID = 0;
                }
            }
            else
            {
                playerData.followSortingMap   = false;
                playerData.customSortingMapID = 0;
            }

            return(playerData);
        }
Esempio n. 16
0
        private void Finish()
        {
            bool is2D = false;

            GameObject newCharacterOb = baseObject;
            GameObject newBaseObject  = baseObject;

            if (IsFirstPerson())
            {
                newBaseObject = new GameObject("Player");
                newBaseObject.AddComponent <Paths>();
                newBaseObject.AddComponent <Rigidbody>();
                Player playerScript = newBaseObject.AddComponent <Player>();
                playerScript.animationEngine = animationEngine;
                newBaseObject.tag            = Tags.player;
                CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>();
                capsuleCollider.center = new Vector3(0f, 1f, 0f);
                capsuleCollider.height = 2f;

                GameObject cameraObject = new GameObject("First person camera");
                cameraObject.transform.parent   = newBaseObject.transform;
                cameraObject.transform.position = new Vector3(0f, 1.5f, 0f);
                Camera cam = cameraObject.AddComponent <Camera>();
                cam.enabled = false;
                cameraObject.AddComponent <FirstPersonCamera>();
                return;
            }

            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                string _name = charName;
                if (charName == null || charName.Length == 0)
                {
                    _name = ("My new " + charType.ToString());
                }

                if (!enforce3D)
                {
                    is2D = true;

                    FollowSortingMap followSortingMap = newCharacterOb.AddComponent <FollowSortingMap>();
                    followSortingMap.followSortingMap = true;
                }

                newBaseObject = new GameObject(_name);
                newCharacterOb.transform.parent      = newBaseObject.transform;
                newCharacterOb.transform.position    = Vector3.zero;
                newCharacterOb.transform.eulerAngles = Vector3.zero;
            }

            if (animationEngine == AnimationEngine.Mecanim || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                if (newCharacterOb.GetComponent <Animator>() == null)
                {
                    newCharacterOb.AddComponent <Animator>();
                }
            }
            else if (animationEngine == AnimationEngine.Legacy)
            {
                if (newCharacterOb.GetComponent <Animation>() == null)
                {
                    newCharacterOb.AddComponent <Animation>();
                }
            }

            if (newBaseObject.GetComponent <AudioSource>() == null)
            {
                newBaseObject.AddComponent <AudioSource>();
            }

            if (newBaseObject.GetComponent <Paths>() == null)
            {
                newBaseObject.AddComponent <Paths>();
            }

            AC.Char charScript = null;
            if (charType == CharType.Player)
            {
                charScript        = newBaseObject.AddComponent <Player>();
                newBaseObject.tag = Tags.player;
            }
            else
            {
                charScript = newBaseObject.AddComponent <NPC>();

                if (is2D)
                {
                    BoxCollider2D boxCollider = newCharacterOb.AddComponent <BoxCollider2D>();
                    UnityVersionHandler.SetBoxCollider2DCentre(boxCollider, new Vector2(0f, 1f));
                    boxCollider.size      = new Vector2(1f, 2f);
                    boxCollider.isTrigger = true;
                }
                else
                {
                    CapsuleCollider capsuleCollider = newCharacterOb.AddComponent <CapsuleCollider>();
                    capsuleCollider.center = new Vector3(0f, 1f, 0f);
                    capsuleCollider.height = 2f;
                }
                newCharacterOb.AddComponent <Hotspot>();
                if (is2D)
                {
                    newCharacterOb.GetComponent <Hotspot>().drawGizmos = false;
                }
            }

            if (is2D)
            {
                newBaseObject.AddComponent <CircleCollider2D>();

                if (charType == CharType.Player)
                {
                    if (newBaseObject.GetComponent <Rigidbody2D>() == null)
                    {
                        newBaseObject.AddComponent <Rigidbody2D>();
                    }
                    charScript.ignoreGravity = true;
                }
            }
            else
            {
                if (newBaseObject.GetComponent <Rigidbody>() == null)
                {
                    newBaseObject.AddComponent <Rigidbody>();
                }
                if (charType == CharType.Player)
                {
                    CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>();
                    capsuleCollider.center = new Vector3(0f, 1f, 0f);
                    capsuleCollider.height = 2f;
                }
            }

            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                charScript.spriteChild = newCharacterOb.transform;
            }

            if (charType == CharType.Player && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.hotspotDetection == HotspotDetection.PlayerVicinity)
            {
                GameObject detectorOb = new GameObject("HotspotDetector");
                detectorOb.transform.parent   = newBaseObject.transform;
                detectorOb.transform.position = Vector3.zero;
                detectorOb.AddComponent <DetectHotspots>();

                if (is2D)
                {
                    CircleCollider2D circleCollider = detectorOb.AddComponent <CircleCollider2D>();
                    circleCollider.isTrigger = true;
                }
                else
                {
                    SphereCollider sphereCollider = detectorOb.AddComponent <SphereCollider>();
                    sphereCollider.isTrigger = true;
                }
            }

            charScript.animationEngine = animationEngine;
            if (animationEngine == AC.AnimationEngine.Custom)
            {
                charScript.customAnimationClass = customAnimationClass;
            }
            charScript.speechLabel = charName;

            GameObject soundChild = new GameObject("Sound child");

            soundChild.transform.parent = newBaseObject.transform;
            soundChild.AddComponent <AudioSource>();
            Sound sound = soundChild.AddComponent <Sound>();

            charScript.soundChild = sound;

            baseObject = null;
            charName   = "";
            EditorGUIUtility.PingObject(newBaseObject);
        }
Esempio n. 17
0
 protected static int SortByScreenPosition(FollowSortingMap o1, FollowSortingMap o2)
 {
     return(KickStarter.CameraMain.WorldToScreenPoint(o1.transform.position).y.CompareTo(KickStarter.CameraMain.WorldToScreenPoint(o2.transform.position).y));
 }