Ejemplo n.º 1
0
        private List <ScriptData> PopulateScriptData(SubScene subScene)
        {
            List <ScriptData> allScriptData = new List <ScriptData>();

            Remember[] scripts = UnityVersionHandler.GetOwnSceneComponents <Remember> ((subScene != null) ? subScene.gameObject : null);

            foreach (Remember _script in scripts)
            {
                Player associatedPlayer = _script.gameObject.GetComponentInParent <Player>();
                if (associatedPlayer != null && !associatedPlayer.IsLocalPlayer())
                {
                    // Skip this, since this is saved in PlayerData
                    continue;
                }

                if (_script.constantID != 0)
                {
                    allScriptData.Add(new ScriptData(_script.constantID, _script.SaveData()));
                }
                else
                {
                    ACDebug.LogWarning("GameObject " + _script.name + " was not saved because its ConstantID has not been set!", _script);
                }
            }

            return(allScriptData);
        }
Ejemplo n.º 2
0
        /**
         * <summary>Assigns a new target (NPC or Player) to start following.</summary>
         * <param name = "_followTarget">The target to follow</param>
         * <param name = "_followTargetIsPlayer">If True, the NPC will follow the current Player, and _followTarget will be ignored</param>
         * <param name = "_followFrequency">The frequency with which to follow the target</param>
         * <param name = "_followDistance">The minimum distance to keep from the target</param>
         * <param name = "_followDistanceMax">The maximum distance to keep from the target</param>
         * <param name = "_faceWhenIdle">If True, the NPC will face the target when idle</param>
         * <param name = "_followRandomDirection">If True, the character will walk to points randomly in the target's vicinity, as opposed to directly towards them</param>
         * <param name = "_followAcrossScenes">If True, and if the character ia an inactive Player, and if they are following the active Player, they can follow the Player across scenes</param>
         */
        public void FollowAssign(Char _followTarget, bool _followTargetIsPlayer, float _followFrequency, float _followDistance, float _followDistanceMax, bool _faceWhenIdle = false, bool _followRandomDirection = true, bool _followAcrossScenes = false)
        {
            if (_followTargetIsPlayer)
            {
                _followTarget = KickStarter.player;
            }

            if (_followTarget == null || _followFrequency <= 0f || _followDistance <= 0f || _followDistanceMax <= 0f)
            {
                StopFollowing();

                if (_followTarget == null)
                {
                    ACDebug.LogWarning("NPC " + name + " cannot follow because no target was set.", this);
                }
                else if (_followFrequency <= 0f)
                {
                    ACDebug.LogWarning("NPC " + name + " cannot follow because frequency was zero.", this);
                }
                else if (_followDistance <= 0f)
                {
                    ACDebug.LogWarning("NPC " + name + " cannot follow because distance was zero.", this);
                }
                else if (_followDistanceMax <= 0f)
                {
                    ACDebug.LogWarning("NPC " + name + " cannot follow because max distance was zero.", this);
                }
                return;
            }

            followTarget          = _followTarget;
            followTargetIsPlayer  = _followTargetIsPlayer;
            followFrequency       = _followFrequency;
            followUpdateTimer     = followFrequency;
            followDistance        = _followDistance;
            followDistanceMax     = _followDistanceMax;
            followFaceWhenIdle    = _faceWhenIdle;
            followRandomDirection = _followRandomDirection;

            followAcrossScenes = false;
            if (_followAcrossScenes && _followTarget == KickStarter.player && this is Player)
            {
                Player thisPlayer = (Player)this;
                if (!thisPlayer.IsLocalPlayer())
                {
                    followAcrossScenes = true;
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            Player _target = (Player)target;

            SharedGUIOne(_target);

            SettingsManager settingsManager = AdvGame.GetReferences().settingsManager;

            if (settingsManager != null && settingsManager.playerSwitching == PlayerSwitching.Allow)
            {
                NPC_GUI(_target);
            }

            SharedGUITwo(_target);

            if (settingsManager && (settingsManager.hotspotDetection == HotspotDetection.PlayerVicinity || settingsManager.playerSwitching == PlayerSwitching.Allow))
            {
                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.LabelField("Player settings", EditorStyles.boldLabel);

                if (settingsManager.hotspotDetection == HotspotDetection.PlayerVicinity)
                {
                    _target.hotspotDetector = (DetectHotspots)CustomGUILayout.ObjectField <DetectHotspots> ("Hotspot detector child:", _target.hotspotDetector, true, "", "The DetectHotspots component to rely on for hotspot detection. This should be a child object of the Player.");
                }

                if (settingsManager.playerSwitching == PlayerSwitching.Allow)
                {
                    _target.autoSyncHotspotState = CustomGUILayout.Toggle("Auto-sync Hotspot state?", _target.autoSyncHotspotState, "", "If True, then any attached Hotspot will be made inactive while this character is the current active Player");
                }

                EditorGUILayout.EndVertical();
            }

            if (Application.isPlaying && _target.gameObject.activeInHierarchy)
            {
                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.LabelField("Current inventory", EditorStyles.boldLabel);

                bool isCarrying = false;

                if (KickStarter.saveSystem != null)
                {
                    if ((_target.IsLocalPlayer() ||
                         KickStarter.settingsManager.playerSwitching == PlayerSwitching.DoNotAllow ||
                         _target.ID == KickStarter.saveSystem.CurrentPlayerID ||
                         KickStarter.settingsManager.shareInventory))
                    {
                        if (KickStarter.runtimeInventory != null && KickStarter.runtimeInventory.localItems != null)
                        {
                            if (ListItems(KickStarter.runtimeInventory.localItems))
                            {
                                isCarrying = true;
                            }
                        }

                        if (KickStarter.inventoryManager != null && KickStarter.runtimeDocuments != null && KickStarter.runtimeDocuments.GetCollectedDocumentIDs() != null)
                        {
                            for (int i = 0; i < KickStarter.runtimeDocuments.GetCollectedDocumentIDs().Length; i++)
                            {
                                Document document = KickStarter.inventoryManager.GetDocument(KickStarter.runtimeDocuments.GetCollectedDocumentIDs()[i]);

                                if (document != null)
                                {
                                    isCarrying = true;

                                    EditorGUILayout.BeginHorizontal();
                                    EditorGUILayout.LabelField("Document:", GUILayout.Width(80f));
                                    EditorGUILayout.LabelField(document.Title, EditorStyles.boldLabel);
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }

                        if (KickStarter.inventoryManager != null && KickStarter.runtimeObjectives != null)
                        {
                            ObjectiveInstance[] objectiveInstances = KickStarter.runtimeObjectives.GetObjectives();
                            foreach (ObjectiveInstance objectiveInstance in objectiveInstances)
                            {
                                EditorGUILayout.BeginHorizontal();
                                EditorGUILayout.LabelField("Objective:", GUILayout.Width(80f));
                                EditorGUILayout.LabelField(objectiveInstance.Objective.GetTitle() + ": " + objectiveInstance.CurrentState.GetLabel(), EditorStyles.boldLabel);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                    else
                    {
                        PlayerData playerData = KickStarter.saveSystem.GetPlayerData(_target.ID);
                        if (playerData != null)
                        {
                            List <InvItem> items = KickStarter.saveSystem.AssignInventory(playerData.inventoryData);
                            if (ListItems(items))
                            {
                                isCarrying = true;
                            }

                            if (!string.IsNullOrEmpty(playerData.collectedDocumentData))
                            {
                                EditorGUILayout.LabelField("Documents:", playerData.collectedDocumentData);
                            }
                            if (!string.IsNullOrEmpty(playerData.playerObjectivesData))
                            {
                                EditorGUILayout.LabelField("Objectives:", playerData.playerObjectivesData);
                            }
                        }
                    }
                }

                if (!isCarrying)
                {
                    EditorGUILayout.HelpBox("This Player is not carrying any items.", MessageType.Info);
                }

                EditorGUILayout.EndVertical();
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }