public void MakePrefab()
        {
            var prefabCommand = ThisCommand as Command;

            if (MakeStateMachineService.ExistTypeInThisProject(prefabCommand.ServiceName + "StateMachine", out Type stmType) &&
                MakeStateMachineService.ExistTypeInThisProject(prefabCommand.ServiceName + "Installer", out Type installerType))
            {
                var obj  = Resources.Load <GameObject>("StateMachineServiceTemp");
                var game = PrefabUtility.InstantiateAttachedAsset(obj) as GameObject;
                game.AddComponent(stmType);
                game.AddComponent(installerType);

                prefabCommand.Settings.SetFirstStateNodeGameObject(prefabCommand.FirstStateGameObject);

                var nodeList  = game.GetComponent <StateNodeList>();
                var installer = game.GetComponent <Installer>();
                var stm       = game.GetComponent <PaupawsanStateMachine>();

                nodeList.SetStateNodeSettings(prefabCommand.Settings);
                installer.m_prefabSettings = prefabCommand.prefabInstallSettings;
                UnityEventTools.AddObjectPersistentListener(installer.m_onInstalled, new UnityAction <GameObject>(nodeList.Initialize), game);
                UnityEventTools.AddObjectPersistentListener(installer.m_onInstalled, new UnityAction <GameObject>(stm.Initialize), game);

                installer.m_autoInstallHierarchyObject.Add(game);
                installer.m_PrefabRoot = game.transform.GetChild(1);

                EditorUtility.SetDirty(prefabCommand.Settings);
                PrefabUtility.SaveAsPrefabAsset(game, prefabCommand.FilePath + "/" + prefabCommand.ServiceName + "StateMachine.prefab");
                UnityEngine.Object.DestroyImmediate(game);
                AssetDatabase.SaveAssets();
            }
        }
        void TryRegister(DataPoller poller, UnityAction <DataPoller> f)
        {
            if (poller)
            {
                var count = poller.PollEvent.GetPersistentEventCount();
                if (this._clean_empty_no_target_events && count > 0)
                {
                    //poller.PollEvent.RemoveAllListeners(); // Only non-persistant listeners.
                    for (var i = 0; i < count; i++)
                    {
                        if (poller.PollEvent.GetPersistentTarget(i) == null ||
                            poller.PollEvent.GetPersistentMethodName(i) == null)
                        {
                            UnityEventTools.RemovePersistentListener(poller.PollEvent, i);
                        }
                    }
                }

                count = poller.PollEvent.GetPersistentEventCount();
                if (count == 0)
                {
                    UnityEventTools.AddObjectPersistentListener(poller.PollEvent, f, poller);
                    poller.PollEvent.SetPersistentListenerState(0, this._unity_event_call_state);
                }
                else if (count > 0 && poller.PollEvent.GetPersistentTarget(0) != poller)
                {
          #if NEODROID_DEBUG
                    if (this.Debugging)
                    {
                        Debug.Log($"PollEvent on {poller} already has a listeners");
                    }
          #endif
                }
            }
        }
 public void Bind <T>(UnityEvent @event) where T : UnityEngine.Object
 {
     if (value is T)
     {
         UnityEventTools.AddObjectPersistentListener(@event, GetAction <T>(target, setMethodName), (T)value);
     }
     else
     {
         Debug.LogError("unable to assign " + value.GetType());
     }
 }
    public void RefreshListeners()
    {
        MainMenuView mainMenuView = FindObjectOfType <MainMenuView>();

        if (mainMenuView == null)
        {
            Debug.LogWarning("Couldn't find main menu view in hierarchy. Ensure you're in the correct scene");
            return;
        }
        UnityAction <LevelData> levelSelectAction = new UnityAction <LevelData>(mainMenuView.SelectLevel);

        if (levelSelectAction == null)
        {
            Debug.LogWarning("Couldn't find function to select level on interatction handler.");
            return;
        }
        GameObject content = GameObject.Find("Content");

        if (content == null)
        {
            Debug.LogWarning("Couldn't find \"Content\". Skipped adding levelData to buttons. Prehaps the object is disabled.");
            return;
        }
        // Iterate over the content and add button listener to each level
        foreach (Transform child in content.transform)
        {
            Transform levelsInHierarchy = FindDeepChild(child, "Levels");
            string    groupName         = child.name;
            foreach (Transform level in levelsInHierarchy)
            {
                Button    button        = level.GetComponentInChildren <Button>();
                string    levelDataPath = levelDataResourcePath + groupName + "/" + level.GetSiblingIndex();
                LevelData levelData     = Resources.Load <LevelData>(levelDataPath);
                if (levelData == null)
                {
                    Debug.LogWarning(string.Format("Couldn't load LevelData at {0}", levelDataPath));
                }
                int numListeners = button.onClick.GetPersistentEventCount();

                // Remove all listeners just in case some extras got added
                for (int i = 0; i < numListeners; i++)
                {
                    UnityEventTools.RemovePersistentListener(button.onClick, button.onClick.GetPersistentEventCount() - 1);
                }

                // Add new listener with correct levelData
                UnityEventTools.AddObjectPersistentListener <LevelData>(button.onClick, levelSelectAction, levelData);

                // Required because we're modifing a prefab in the heirarchy
                PrefabUtility.RecordPrefabInstancePropertyModifications(button);
            }
        }
    }
Beispiel #5
0
    private void generateEvents(MenuGenerator target)
    {
        UnityAction <GameObject> action;

        action = new UnityAction <GameObject>(target.OnClickPlayGame);
        UnityEventTools.AddObjectPersistentListener <GameObject>(target.playgame.onClick, action, target.playgame.transform.gameObject);

        foreach (PropertyMenuBlockManager p in target.blocks)
        {
            if (p.slider != null)
            {
                action = new UnityAction <GameObject>(p.SliderEvent);
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.slider.onValueChanged, action, p.slider.transform.gameObject);
            }
            if (p.textfield != null)
            {
                action = new UnityAction <GameObject>(p.InputTextEvent);
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.textfield.onEndEdit, action, p.textfield.transform.gameObject);
            }
            if (p.boolfield != null)
            {
                action = new UnityAction <GameObject>(p.TogglerEvent);
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.boolfield.onValueChanged, action, p.boolfield.transform.gameObject);
            }
            if (p.prevButton != null)
            {
                action = new UnityAction <GameObject>(p.PrevButtonEvent);
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.prevButton.onClick, action, p.prevButton.transform.gameObject);
            }
            if (p.nextButton != null)
            {
                action = new UnityAction <GameObject>(p.NextButtonEvent);
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.nextButton.onClick, action, p.nextButton.transform.gameObject);
            }
            if (p.optiondropdown != null)
            {
                if (p.Hasstringoptions)
                {
                    action = new UnityAction <GameObject>(p.StringOptionEvent);
                }
                else
                {
                    action = new UnityAction <GameObject>(p.DropdownEvent);
                }
                UnityEventTools.AddObjectPersistentListener <GameObject>(p.optiondropdown.onValueChanged, action, p.optiondropdown.transform.gameObject);
            }
        }
    }
Beispiel #6
0
    /// <summary>
    /// Add an action to the UnityEvent displayed in the editor.
    /// </summary>
    /// <param name="button">The object that will listen to the event.</param>
    /// <param name="action">The action to trigger.</param>
    /// <returns>Success state.</returns>
    public static bool AddPersistentEvent <T>(this UnityEvent @event, UnityEngine.Object caller, UnityAction <T> method, T argument) where T : UnityEngine.Object
    {
#if !UNITY_EDITOR
        return(false);
#else
        if (@event.HasCall(caller, method.Method.Name))
        {
            return(false);
        }
        var             targetInfo     = UnityEventBase.GetValidMethodInfo(caller, method.Method.Name, new Type[] { typeof(UnityEngine.Object) });
        UnityAction <T> methodDelegate = Delegate.CreateDelegate(typeof(UnityAction <T>), caller, targetInfo) as UnityAction <T>;
        UnityEventTools.AddObjectPersistentListener(@event, methodDelegate, argument);

        UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
#endif
        return(true);
    }
Beispiel #7
0
        // VALIDATE: ------------------------------------------------------------------------------

        #if UNITY_EDITOR
        private new void OnValidate()
        {
            base.OnValidate();

            if (this.actions == null)
            {
                this.actions = gameObject.GetComponent <Actions>();
                if (this.actions == null)
                {
                    return;
                }

                this.onClick.RemoveAllListeners();
                UnityEventTools.AddObjectPersistentListener <GameObject>(
                    this.onClick,
                    this.actions.ExecuteWithTarget,
                    gameObject
                    );
            }

            this.actions.hideFlags = HideFlags.HideInInspector;
        }
    // Start is called before the first frame update
    void Start()
    {
        var sr = GetComponent <SpriteRenderer>();

        if (sr != null)
        {
            sr.enabled = !IsTrigger;
        }

        // 저장된 데이터와 해당 아이디간의 관계를 따지고
        if (DeleteAfter)
        {
#if DEBUG
            var targetinfo = UnityEventBase.GetValidMethodInfo(DataManager.instance, "SaveTrigger", new Type[] { typeof(GameObject) });
            UnityAction <GameObject> action =
                Delegate.CreateDelegate(typeof(UnityAction <GameObject>), DataManager.instance, targetinfo, false) as UnityAction <GameObject>;
            UnityEventTools.AddObjectPersistentListener(After, action, gameObject);
#else
            After.AddListener(delegate { DataManager.instance.SaveTrigger(gameObject); });
#endif
        }

        if (conditional_Conversations.Count > 0)
        {
            // 반대로 해야하는 이유는, 선행되는 조건에 대화가 묶여있는 것을 예방하기 위함
            for (int i = conditional_Conversations.Count - 1; i > -1; i--)
            {
                bool CanOpen = CheckCondition(conditional_Conversations[i].condition);

                if (CanOpen)
                {
                    index = i;
                    break;
                }
            }
        }

        if (index == -1)
        {
            // 어디까지 대화를 들었는 지 체크
            if (DataManager.Data.isinitialized[3])
            {
                try
                {
                    NPC.initialize(DataManager.Data.NPC_Conversation[NPC.FileName]);
                }
                catch (KeyNotFoundException)
                {
                    NPC.initialize();
                }
            }
            else
            {
                NPC.initialize();
            }
            // 해당 아이디가 가진 대화 스크립트 저장하기
            DataManager.Data.SaveConversation(NPC.FileName, NPC.GetCurrentConversation_ID());
            //Debug.Log(DataManager.Data.NPC_Conversation);
            // 대화 스크립트

            NPC.LoadConversation(NPC.GetCurrentConversation_ID());
        }
        else
        {
            var NPC = conditional_Conversations[index].NPC;

            if (DataManager.Data.isinitialized[3])
            {
                try
                {
                    NPC.initialize(DataManager.Data.NPC_Conversation[NPC.FileName]);
                }
                catch (KeyNotFoundException)
                {
                    NPC.initialize();
                }
            }
            else
            {
                NPC.initialize();
            }

            NPC.LoadConversation(NPC.GetCurrentConversation_ID());
        }
    }
        protected virtual void AddAbilities()
        {
            if (character.GetComponent <DiasGames.ThirdPersonSystem.AnimatorManager>() == null)
            {
                Undo.AddComponent <DiasGames.ThirdPersonSystem.AnimatorManager>(character);
            }

            if (character.GetComponent <DiasGames.ThirdPersonSystem.UnityInputManager>() == null)
            {
                Undo.AddComponent <DiasGames.ThirdPersonSystem.UnityInputManager>(character);
            }

            FreeLocomotion m_FreeLocomotion = character.GetComponent <FreeLocomotion>();

            if (m_FreeLocomotion == null)
            {
                m_FreeLocomotion = Undo.AddComponent <FreeLocomotion>(character);

                SerializedObject locomotion = new SerializedObject(m_FreeLocomotion);

                locomotion.FindProperty("m_IdlePhysicMaterial").objectReferenceValue    = groundFriction;
                locomotion.FindProperty("m_AbilityPhysicMaterial").objectReferenceValue = zeroFriction;

                locomotion.ApplyModifiedProperties();
            }

            Strafe m_Strafe = character.GetComponent <Strafe>();

            if (m_Strafe == null)
            {
                m_Strafe = Undo.AddComponent <Strafe>(character);

                SerializedObject strafe = new SerializedObject(m_Strafe);

                strafe.FindProperty("m_IdleFriction").objectReferenceValue          = groundFriction;
                strafe.FindProperty("m_AbilityPhysicMaterial").objectReferenceValue = zeroFriction;

                strafe.ApplyModifiedProperties();
            }

            DiasGames.ThirdPersonSystem.JumpAbility m_Jump = character.GetComponent <DiasGames.ThirdPersonSystem.JumpAbility>();
            if (m_Jump == null)
            {
                m_Jump = Undo.AddComponent <DiasGames.ThirdPersonSystem.JumpAbility>(character);
                m_Jump.AbilityPhysicMaterial = zeroFriction;

                AudioClip             jumpClip = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/Dias Games/Third Person System/Audio/male_jump.wav");
                CharacterAudioManager manager  = character.GetComponent <CharacterAudioManager>();
                if (manager != null)
                {
                    if (m_Jump.OnEnterAbilityEvent == null)
                    {
                        m_Jump.OnEnterAbilityEvent = new UnityEvent();
                    }

                    UnityEventTools.AddObjectPersistentListener(m_Jump.OnEnterAbilityEvent, manager.PlayVoiceSound, jumpClip);
                }
            }

            DiasGames.ThirdPersonSystem.FallAbility m_Fall = character.GetComponent <DiasGames.ThirdPersonSystem.FallAbility>();
            if (m_Fall == null)
            {
                m_Fall = Undo.AddComponent <DiasGames.ThirdPersonSystem.FallAbility>(character);
                m_Fall.AbilityPhysicMaterial = zeroFriction;
            }

            DiasGames.ThirdPersonSystem.RollAbility m_Roll = character.GetComponent <DiasGames.ThirdPersonSystem.RollAbility>();
            if (m_Roll == null)
            {
                m_Roll = Undo.AddComponent <DiasGames.ThirdPersonSystem.RollAbility>(character);
            }


            DiasGames.ThirdPersonSystem.CrouchAbility m_Crouch = character.GetComponent <DiasGames.ThirdPersonSystem.CrouchAbility>();
            if (m_Crouch == null)
            {
                m_Crouch = Undo.AddComponent <DiasGames.ThirdPersonSystem.CrouchAbility>(character);
            }

            m_Crouch.AbilityPhysicMaterial = groundFriction;

            CrawlAbility m_Crawl = character.GetComponent <CrawlAbility>();

            if (m_Crawl == null)
            {
                m_Crawl = Undo.AddComponent <CrawlAbility>(character);
            }

            m_Crawl.AbilityPhysicMaterial = groundFriction;
            // -------------------------- SET IGNORE ABILITIES ---------------------------------- //

            // Strafe
            AddIgnoreAbility(m_Strafe, m_FreeLocomotion);

            // Jump
            AddIgnoreAbility(m_Jump, m_FreeLocomotion);
            AddIgnoreAbility(m_Jump, m_Strafe);

            // Roll
            AddIgnoreAbility(m_Roll, m_FreeLocomotion);
            AddIgnoreAbility(m_Roll, m_Strafe);
            AddIgnoreAbility(m_Roll, m_Crouch);

            //Crouch
            AddIgnoreAbility(m_Crouch, m_FreeLocomotion);
            AddIgnoreAbility(m_Crouch, m_Strafe);
            AddIgnoreAbility(m_Crouch, m_Crawl);

            //Crawl
            AddIgnoreAbility(m_Crawl, m_FreeLocomotion);
            AddIgnoreAbility(m_Crawl, m_Strafe);
            AddIgnoreAbility(m_Crawl, m_Crouch);

            // -------------------------------------------------------------------------------- //
        }
 public static void AddPersistentListener <T>(this UnityEventBase self, UnityAction <T> unityAction, T argument)
     where T : UObject
 {
     UnityEventTools.AddObjectPersistentListener(self, unityAction, argument);
 }
Beispiel #11
0
        protected override void AddAbilities()
        {
            base.AddAbilities();

            CharacterAudioManager audioManager = character.GetComponent <CharacterAudioManager>();

            AudioClip hopHorizontalClip = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/Dias Games/Climbing System/Audio/male_hop_horizontal.wav");
            AudioClip hopUpClip         = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/Dias Games/Climbing System/Audio/male_hop_up.wav");
            AudioClip jumpClip          = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/Dias Games/Third Person System/Audio/male_jump.wav");

            FreeLocomotion m_FreeLocomotion = character.GetComponent <FreeLocomotion>();
            Strafe         m_Strafe         = character.GetComponent <Strafe>();
            JumpAbility    m_Jump           = character.GetComponent <JumpAbility>();
            FallAbility    m_Fall           = character.GetComponent <FallAbility>();
            CrouchAbility  m_Crouch         = character.GetComponent <CrouchAbility>();

            LayerMask m_FootLayers = (1 << 0) | (1 << 14) | (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20) | (1 << 25) | (1 << 26);

            // Vault ability
            ClimbingSystem.VaultAbility m_Vault = character.GetComponent <ClimbingSystem.VaultAbility>();
            if (m_Vault == null)
            {
                m_Vault = Undo.AddComponent <ClimbingSystem.VaultAbility>(character);

                if (m_Vault.OnEnterAbilityEvent == null)
                {
                    m_Vault.OnEnterAbilityEvent = new UnityEvent();
                }

                UnityEventTools.AddObjectPersistentListener(m_Vault.OnEnterAbilityEvent, audioManager.PlayVoiceSound, hopHorizontalClip);
            }

            m_Vault.ClimbingMask = (1 << 21);
            ////

            // Step Up ability Setup
            ClimbingSystem.StepUpAbility m_StepUp = character.GetComponent <ClimbingSystem.StepUpAbility>();
            if (m_StepUp == null)
            {
                m_StepUp = Undo.AddComponent <ClimbingSystem.StepUpAbility>(character);
            }

            m_StepUp.ClimbingMask = (1 << 16);
            ////

            // Half Climb ability Setup
            ClimbingSystem.LowerClimbAbility m_LowerClimb = character.GetComponent <ClimbingSystem.LowerClimbAbility>();
            if (m_LowerClimb == null)
            {
                m_LowerClimb = Undo.AddComponent <ClimbingSystem.LowerClimbAbility>(character);

                if (m_LowerClimb.OnEnterAbilityEvent == null)
                {
                    m_LowerClimb.OnEnterAbilityEvent = new UnityEvent();
                }

                UnityEventTools.AddObjectPersistentListener(m_LowerClimb.OnEnterAbilityEvent, audioManager.PlayVoiceSound, hopUpClip);
            }

            m_LowerClimb.ClimbingMask = (1 << 17);
            ////

            // Climbing ability setup
            ClimbingSystem.ClimbingAbility m_Climbing = character.GetComponent <ClimbingSystem.ClimbingAbility>();
            if (m_Climbing == null)
            {
                m_Climbing = Undo.AddComponent <ClimbingSystem.ClimbingAbility>(character);
            }

            SerializedObject climb = new SerializedObject(m_Climbing);

            climb.FindProperty("m_ClimbableMask").intValue = (1 << 18) | (1 << 19);
            climb.FindProperty("m_CharacterOffsetFromLedge").vector3Value = new Vector3(0, CharacterHeight - 0.4f, 0.3f);
            climb.FindProperty("m_CharacterOffsetOnHang").vector3Value    = new Vector3(0, CharacterHeight - 0.45f, 0.3f);
            climb.ApplyModifiedProperties();
            ////
            ///
            // Climb Jump ability setup
            ClimbingSystem.ClimbJump m_ClimbJump = character.GetComponent <ClimbingSystem.ClimbJump>();
            if (m_ClimbJump == null)
            {
                m_ClimbJump = Undo.AddComponent <ClimbingSystem.ClimbJump>(character);

                if (m_ClimbJump.OnEnterAbilityEvent == null)
                {
                    m_ClimbJump.OnEnterAbilityEvent = new UnityEvent();
                }

                UnityEventTools.AddObjectPersistentListener(m_ClimbJump.OnEnterAbilityEvent, audioManager.PlayVoiceSound, jumpClip);
            }

            ////
            ///
            ClimbingSystem.DropToClimbAbility m_DropToClimb = character.GetComponent <ClimbingSystem.DropToClimbAbility>();
            if (m_DropToClimb == null)
            {
                m_DropToClimb = Undo.AddComponent <ClimbingSystem.DropToClimbAbility>(character);
            }

            m_DropToClimb.DroppableLayer = (1 << 19) | (1 << 20);

            ClimbingSystem.LadderAbility m_Ladder = character.GetComponent <ClimbingSystem.LadderAbility>();
            if (m_Ladder == null)
            {
                m_Ladder = Undo.AddComponent <ClimbingSystem.LadderAbility>(character);
            }

            WallRun m_WallRun = character.GetComponent <WallRun>();

            if (m_WallRun == null)
            {
                m_WallRun = Undo.AddComponent <WallRun>(character);
            }

            WallClimb m_WallClimb = character.GetComponent <WallClimb>();

            if (m_WallClimb == null)
            {
                m_WallClimb = Undo.AddComponent <WallClimb>(character);
            }

            // -------------------------- SET IGNORE ABILITIES ---------------------------------- //

            // Climb ladder
            AddIgnoreAbility(m_Ladder, m_FreeLocomotion);
            AddIgnoreAbility(m_Ladder, m_Strafe);
            AddIgnoreAbility(m_Ladder, m_Fall);
            AddIgnoreAbility(m_Ladder, m_Jump);
            AddIgnoreAbility(m_Ladder, m_ClimbJump);

            // Step up
            AddIgnoreAbility(m_StepUp, m_FreeLocomotion);
            AddIgnoreAbility(m_StepUp, m_Strafe);

            // Lower climb
            AddIgnoreAbility(m_LowerClimb, m_FreeLocomotion);
            AddIgnoreAbility(m_LowerClimb, m_Strafe);
            AddIgnoreAbility(m_LowerClimb, m_Fall);
            AddIgnoreAbility(m_LowerClimb, m_ClimbJump);
            AddIgnoreAbility(m_LowerClimb, m_Jump);

            // Climbing
            AddIgnoreAbility(m_Climbing, m_Fall);
            AddIgnoreAbility(m_Climbing, m_Jump);
            AddIgnoreAbility(m_Climbing, m_ClimbJump);

            // Drop to climb
            AddIgnoreAbility(m_DropToClimb, m_FreeLocomotion);
            AddIgnoreAbility(m_DropToClimb, m_Strafe);
            AddIgnoreAbility(m_DropToClimb, m_Crouch);

            // Vault
            AddIgnoreAbility(m_Vault, m_FreeLocomotion);
            AddIgnoreAbility(m_Vault, m_Strafe);
            AddIgnoreAbility(m_Vault, m_Jump);
            AddIgnoreAbility(m_Vault, m_Fall);
            AddIgnoreAbility(m_Vault, m_Crouch);

            // Climb Jump
            AddIgnoreAbility(m_ClimbJump, m_FreeLocomotion);
            AddIgnoreAbility(m_ClimbJump, m_Strafe);
            AddIgnoreAbility(m_ClimbJump, m_Jump);
            AddIgnoreAbility(m_ClimbJump, m_Climbing);
            AddIgnoreAbility(m_ClimbJump, m_Ladder);
            AddIgnoreAbility(m_ClimbJump, m_WallClimb);

            // Wall Run
            AddIgnoreAbility(m_WallRun, m_Jump);
            AddIgnoreAbility(m_WallRun, m_ClimbJump);

            // Wall Climb
            AddIgnoreAbility(m_WallClimb, m_ClimbJump);
            AddIgnoreAbility(m_WallClimb, m_WallRun);
            AddIgnoreAbility(m_WallClimb, m_Jump);
            AddIgnoreAbility(m_WallClimb, m_Fall);
            AddIgnoreAbility(m_WallClimb, m_DropToClimb);

            // -------------------------------------------------------------------------------- //
        }