Esempio n. 1
0
        /// <summary>
        /// Initialize ability and get all references that an ability needs to run
        /// </summary>
        /// <param name="mainSystem"></param>
        /// <param name="animatorManager"></param>
        /// <param name="inputManager"></param>
        public virtual void Initialize(ThirdPersonSystem mainSystem, AnimatorManager animatorManager, UnityInputManager inputManager)
        {
            m_System          = mainSystem;
            m_AnimatorManager = animatorManager;
            m_InputManager    = inputManager;

            m_InputToEnter = m_InputManager.GetInputReference(InputButton);
        }
        private void Awake()
        {
            m_System = GetComponent <ThirdPersonSystem>();

            // Initialize each modifier attached to character
            foreach (Modifier mod in m_Modifiers)
            {
                mod.Initialize(m_System);
            }
        }
        private void OnEnable()
        {
            m_GroundMask = serializedObject.FindProperty("m_GroundMask");
            customProperties.Add(m_GroundMask.name);

            m_GroundCheckDistance = serializedObject.FindProperty("m_GroundCheckDistance");
            customProperties.Add(m_GroundCheckDistance.name);

            m_MaxAngleSlope = serializedObject.FindProperty("m_MaxAngleSlope");
            customProperties.Add(m_MaxAngleSlope.name);



            m_ApplyExtraGravity = serializedObject.FindProperty("m_ApplyExtraGravity");
            customProperties.Add(m_ApplyExtraGravity.name);

            m_GravityMultiplier = serializedObject.FindProperty("m_GravityMultiplier");
            customProperties.Add(m_GravityMultiplier.name);



            alwaysZoomProperty = serializedObject.FindProperty("m_AlwaysZoomCamera");
            customProperties.Add(alwaysZoomProperty.name);



            OnAnyAbilityEnters = serializedObject.FindProperty("OnAnyAbilityEnters");
            customProperties.Add(OnAnyAbilityEnters.name);

            OnAnyAbilityExits = serializedObject.FindProperty("OnAnyAbilityExits");
            customProperties.Add(OnAnyAbilityExits.name);


            m_BehavioursToDisable = serializedObject.FindProperty("m_BehavioursToDisable");
            customProperties.Add(m_BehavioursToDisable.name);

            m_Controller = target as global::DiasGames.ThirdPersonSystem.ThirdPersonSystem;

            icon        = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Dias Games/Editor/GUI/tps_icon.psd", typeof(Texture2D));
            customSkin  = Resources.Load("HeaderSkin") as GUISkin;
            contentSkin = Resources.Load("ContentSkin") as GUISkin;
        }
Esempio n. 4
0
 public virtual void Initialize(ThirdPersonSystem system)
 {
     m_System = system;
 }
Esempio n. 5
0
        public void BuildCharacter()
        {
            if (updateLayers)
            {
                UpdateLayers();
            }

            zeroFriction   = AssetDatabase.LoadAssetAtPath <PhysicMaterial>("Assets/Dias Games/Third Person System/Physics Materials/ZeroFriction.physicMaterial");
            groundFriction = AssetDatabase.LoadAssetAtPath <PhysicMaterial>("Assets/Dias Games/Third Person System/Physics Materials/GroundFriction.physicMaterial");

            #region Set Tag and Layer

            character.tag   = "Player";
            character.layer = 15;

            #endregion

            #region Animator Builder
            m_Animator = character.GetComponent <Animator>();
            if (m_Animator == null)
            {
                m_Animator = character.AddComponent <Animator>();
            }

            m_Animator.updateMode = AnimatorUpdateMode.AnimatePhysics;
            m_Animator.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath <RuntimeAnimatorController>("Assets/Dias Games/Third Person System/Animator/Third Person Animator.controller");
            #endregion

            #region Rigidbody Builder
            Rigidbody m_Rigidbody = character.GetComponent <Rigidbody>();
            if (m_Rigidbody == null)
            {
                m_Rigidbody = character.AddComponent <Rigidbody>();
            }

            m_Rigidbody.angularDrag = 0;
            m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
            #endregion

            #region Capsule Collider Builder
            CapsuleCollider m_Capsule = character.GetComponent <CapsuleCollider>();
            if (m_Capsule == null)
            {
                m_Capsule = character.AddComponent <CapsuleCollider>();
            }

            m_Capsule.radius   = 0.3f;
            m_Capsule.height   = 1.8f;
            m_Capsule.center   = new Vector3(0, m_Capsule.height * 0.5f, 0);
            m_Capsule.material = zeroFriction;
            #endregion

            #region Audio Builder

            AudioSource audio = character.GetComponent <AudioSource>();
            if (audio == null)
            {
                audio = character.AddComponent <AudioSource>();
            }
            audio.playOnAwake = false;

            #endregion

            #region Create Character Component

            ThirdPersonSystem m_Controller = character.GetComponent <ThirdPersonSystem>();
            if (m_Controller == null)
            {
                m_Controller = character.AddComponent <ThirdPersonSystem>();
            }

            m_Controller.GroundMask = (1 << 0) | (1 << 14) | (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20);

            HealthManager healthManager = character.GetComponent <HealthManager>();
            if (healthManager == null)
            {
                healthManager = character.AddComponent <HealthManager>();
            }

            #endregion

            AddAbilities();
        }
        protected override void OnEnable()
        {
            base.OnEnable();
            m_Controller = target as ThirdPersonSystem;

            m_GroundMask = serializedObject.FindProperty("m_GroundMask");
            customProperties.Add(m_GroundMask.name);

            m_GroundCheckDistance = serializedObject.FindProperty("m_GroundCheckDistance");
            customProperties.Add(m_GroundCheckDistance.name);

            m_MaxAngleSlope = serializedObject.FindProperty("m_MaxAngleSlope");
            customProperties.Add(m_MaxAngleSlope.name);

            gravityAcc = serializedObject.FindProperty("m_GravityAcceleration");
            customProperties.Add(gravityAcc.name);

            alwaysZoomProperty = serializedObject.FindProperty("m_AlwaysZoomCamera");
            customProperties.Add(alwaysZoomProperty.name);

            OnAnyAbilityEnters = serializedObject.FindProperty("OnAnyAbilityEnters");
            customProperties.Add(OnAnyAbilityEnters.name);

            OnAnyAbilityExits = serializedObject.FindProperty("OnAnyAbilityExits");
            customProperties.Add(OnAnyAbilityExits.name);

            OnGroundedEvent = serializedObject.FindProperty("OnGrounded");
            customProperties.Add(OnGroundedEvent.name);

            if (EditorPrefs.HasKey("Selection"))
            {
                selection = (Selection)EditorPrefs.GetInt("Selection");
            }

            if (EditorPrefs.HasKey("SelectedAbility"))
            {
                selectedAbility = EditorPrefs.GetInt("SelectedAbility");
            }

            if (EditorPrefs.HasKey("AbilitySelection"))
            {
                m_AbilitySection = (DrawSection)EditorPrefs.GetInt("AbilitySelection");
            }

            UpdateAbilitiesList();

            allAvailablesAbilities.Clear();
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            for (int i = 0; i < assemblies.Length; i++)
            {
                var types = assemblies[i].GetTypes();
                for (int j = 0; j < types.Length; ++j)
                {
                    // Must derive from Modifier.
                    if (!typeof(ThirdPersonAbility).IsAssignableFrom(types[j]))
                    {
                        continue;
                    }

                    // Ignore abstract classes.
                    if (types[j].IsAbstract)
                    {
                        continue;
                    }

                    allAvailablesAbilities.Add(types[j]);
                }
            }

            Undo.undoRedoPerformed += UpdateAbilitiesList;
        }
Esempio n. 7
0
        public override void Initialize(ThirdPersonSystem mainSystem, AnimatorManager animatorManager, UnityInputManager inputManager)
        {
            base.Initialize(mainSystem, animatorManager, inputManager);

            m_Camera = Camera.main.transform;
        }
        public virtual void BuildCharacter()
        {
            zeroFriction   = AssetDatabase.LoadAssetAtPath <PhysicMaterial>("Assets/Dias Games/Third Person System/Physics Materials/ZeroFriction.physicMaterial");
            groundFriction = AssetDatabase.LoadAssetAtPath <PhysicMaterial>("Assets/Dias Games/Third Person System/Physics Materials/GroundFriction.physicMaterial");

            #region Set Tag and Layer

            character.tag   = "Player";
            character.layer = 15;

            #endregion

            #region Animator Builder
            m_Animator = character.GetComponent <Animator>();
            if (m_Animator == null)
            {
                m_Animator = Undo.AddComponent <Animator>(character);
            }

            m_Animator.updateMode  = AnimatorUpdateMode.AnimatePhysics;
            m_Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

            m_Animator.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath <RuntimeAnimatorController>(m_AnimatorPath);

            #endregion

            #region Rigidbody Builder
            Rigidbody m_Rigidbody = character.GetComponent <Rigidbody>();
            if (m_Rigidbody == null)
            {
                m_Rigidbody = Undo.AddComponent <Rigidbody>(character);
            }

            m_Rigidbody.angularDrag = 0;
            m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
            #endregion

            #region Capsule Collider Builder
            CapsuleCollider m_Capsule = character.GetComponent <CapsuleCollider>();
            if (m_Capsule == null)
            {
                m_Capsule = Undo.AddComponent <CapsuleCollider>(character);
            }

            m_Capsule.radius   = 0.3f;
            m_Capsule.height   = CharacterHeight;
            m_Capsule.center   = new Vector3(0, m_Capsule.height * 0.5f, 0);
            m_Capsule.material = zeroFriction;
            #endregion

            #region Audio Builder

            CharacterAudioManager audio = character.GetComponent <CharacterAudioManager>();
            if (audio == null)
            {
                audio = Undo.AddComponent <CharacterAudioManager>(character);

                GameObject effectSource = new GameObject("Effect Audio Source");
                effectSource.transform.parent        = character.transform;
                effectSource.transform.localPosition = Vector3.zero;

                // Create audio sources on character
                AudioSource voice  = Undo.AddComponent <AudioSource>(m_Animator.GetBoneTransform(HumanBodyBones.Head).gameObject);
                AudioSource effect = Undo.AddComponent <AudioSource>(effectSource);

                SerializedObject audioManager = new SerializedObject(audio);

                audioManager.FindProperty("m_VoiceSource").objectReferenceValue  = voice;
                audioManager.FindProperty("m_EffectSource").objectReferenceValue = effect;

                audioManager.ApplyModifiedProperties();
            }
            #endregion

            #region Create Character Component

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

            m_Controller.GroundMask = (1 << 0) | (1 << 14) | (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20) | (1 << 25) | (1 << 26);

            ModifierManager modifierManager = character.GetComponent <ModifierManager>();
            if (modifierManager == null)
            {
                modifierManager = Undo.AddComponent <ModifierManager>(character);
            }

            system   = new SerializedObject(m_Controller);
            modifier = new SerializedObject(modifierManager);

            #endregion

            // Camera Track
            if (character.transform.Find("Camera Track Pos") == null)
            {
                GameObject track = new GameObject("Camera Track Pos");
                Undo.RegisterCreatedObjectUndo(track, "Camera Track Pos");

                track.transform.parent        = character.transform;
                track.transform.localPosition = Vector3.up * 1.5f;
            }

            AddAbilities();

            AddModifiers();
        }