public CharacterBehaviour(string characterID, CharacterState state, bool isSleeper, CharacterBehaviourData data) { this.characterId = characterID; this.state = state; this.isSleeper = isSleeper; this.data = data; }
public override void OnInspectorGUI() { DrawDefaultInspector(); // for other non-HideInInspector fields CharacterBehaviourData script = (CharacterBehaviourData)target; EditorGUILayout.Separator(); if (script.isPlayable) { script.speed = EditorGUILayout.FloatField("Speed", script.speed); script.maxSpeed = EditorGUILayout.FloatField("Max Speed", script.maxSpeed); } if (script.isSleeper) { script.sleeperMotion = EditorGUILayout.ObjectField("Sleeper Motion", script.sleeperMotion, typeof(AnimationClip), true) as AnimationClip; } /* * if(script.hasNextState) * { * script.nextState = (CharacterState)EditorGUILayout.EnumPopup("Next State", script.nextState); * } */ }
private void PreEnter_CharacterController() { behaviours = new Dictionary <int, CharacterBehaviour>(); // ScriptableObject만으로 케릭터 병렬 완성을 가정하자. AnimatorOverrideController newController = new AnimatorOverrideController { name = characterID + "_controller", runtimeAnimatorController = animator.runtimeAnimatorController }; // 여기서 이제 컨트롤러 네이밍 규칙이 정해진다. // 1. 기본은 전부 소문자 // 2. 불붙지 않은 state는 뒤에 _sleeper 가 붙음. // 3. 고유 케릭터 string 전달로 능력치 세분화 가능하도록 만들자. foreach (CharacterState state in Enum.GetValues(typeof(CharacterState))) { if (state == CharacterState.None) { continue; } string stateString = state.ToString().ToLower(); int id = Animator.StringToHash(stateString); // 만약 스크립트별로 별개의 엑션이 필요하다면 // new CharacterBehaviour 대신 상속버전으로 넣어 줄 수 있다. // todo : 나중에 리소스 메니져 통하게 만들기. string path = string.Format("ScriptableObjects/Behaviour/{0}_{1}", characterID, state); CharacterBehaviourData data = (CharacterBehaviourData)Resources.Load(path); if (data == null) { continue; } if (behaviours.ContainsKey(id) == false) { behaviours.Add(id, new CharacterBehaviour(characterID, state, false, data)); newController[stateString] = data.motion; } if (data.isSleeper == false) { continue; } stateString += sleeperPostfix; int sleeperId = Animator.StringToHash(stateString); if (behaviours.ContainsKey(sleeperId) == false) { behaviours.Add(sleeperId, new CharacterBehaviour(characterID, state, true, data)); newController[stateString] = data.sleeperMotion; } } animator.runtimeAnimatorController = newController; animator.SetBool("IsSleeper", isSleeper); }