コード例 #1
0
    private void NewState()
    {
        AlienBaseState state = new AlienBaseState();

        state.Name = "BaseState " + myTarget.StateOrder.Count;

        if (myTarget.StateOrder.Count != 0)
        {
            state.startTime = myTarget.StateOrder[myTarget.StateOrder.Count - 1].endTime;
        }
        else
        {
            state.startTime = myTarget.minNeededTime;
        }

        state.endTime = myTarget.maxNeededTime;

        if (myTarget.currentTestState == myTarget.StateOrder.Count)
        {
            myTarget.currentTestState = myTarget.StateOrder.Count + 1;
        }

        myTarget.StateOrder.Add(state);

        UpdateStateList();
    }
コード例 #2
0
    private void UpdateStateTimeAfter(int index)
    {
        if (index < myTarget.StateOrder.Count - 1)
        {
            AlienBaseState state     = myTarget.StateOrder[index];
            AlienBaseState nextState = myTarget.StateOrder[index + 1];

            nextState.startTime = state.endTime;

            if (nextState.startTime > nextState.endTime)
            {
                nextState.endTime = nextState.startTime;
            }

            UpdateStateTimeAfter(index + 1);
        }
    }
コード例 #3
0
    private void UpdateStateTimeBefore(int index)
    {
        if (index >= 1)
        {
            AlienBaseState state     = myTarget.StateOrder[index];
            AlienBaseState lastState = myTarget.StateOrder[index - 1];

            lastState.endTime = state.startTime;

            if (lastState.endTime < lastState.startTime)
            {
                lastState.startTime = lastState.endTime;
            }

            UpdateStateTimeBefore(index - 1);
        }
    }
コード例 #4
0
    private void DrawInspectorForState(AlienBaseState state)
    {
        state.Name = EditorGUILayout.TextField(state.Name);

        EditorGUILayout.LabelField(myTarget.transform.childCount.ToString());

        state.healthBonus = EditorGUILayout.IntSlider("HealthBonus", (int)state.healthBonus, 0, 300);

        EditorGUILayout.MinMaxSlider(new GUIContent("Start/End Time"), ref state.startTime, ref state.endTime, myTarget.minNeededTime, myTarget.maxNeededTime);
        state.startTime = EditorGUILayout.FloatField("Start Time:", state.startTime);
        state.endTime   = EditorGUILayout.FloatField("End Time:", state.endTime);

        state.spawning = EditorGUILayout.Toggle("Spawning", state.spawning);
        if (state.spawning)
        {
            state.spawnCooldown = EditorGUILayout.FloatField("Spawn Cooldown:", state.spawnCooldown);

            spawningInfoScrollValue = EditorGUILayout.BeginScrollView(spawningInfoScrollValue, GUILayout.MaxHeight(300), GUILayout.MinHeight(80));

            state.Range = EditorGUILayout.FloatField("Range:", state.Range);

            //state.HitAbleFindMask = LayerMaskField("Mask:", state.HitAbleFindMask, false);

            SpawnInfo deleteInfo = null;

            if (state.spawnInfos == null)
            {
                state.spawnInfos = new List <SpawnInfo>();
            }

            foreach (var spawnInfo in state.spawnInfos)
            {
                spawnInfo.poolName = EditorGUILayout.TextField("PoolName:", spawnInfo.poolName);
                spawnInfo.weight   = EditorGUILayout.FloatField("SpawnWeight:", spawnInfo.weight);
                if (GUILayout.Button("Delete SpawnInfo"))
                {
                    deleteInfo = spawnInfo;
                }
            }

            if (deleteInfo != null)
            {
                state.spawnInfos.Remove(deleteInfo);
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Add SpawnInfo"))
            {
                state.spawnInfos.Add(new SpawnInfo());
            }
        }

        if (GUILayout.Button("Delete State"))
        {
            deleteStateIndex = currentStateIndex;
        }

        if (GUI.changed)
        {
            if (state.startTime < 0)
            {
                state.startTime = 0;
            }

            if (currentStateIndex == 0)
            {
                state.startTime = myTarget.minNeededTime;
                if (myTarget.StateCount == 1)
                {
                    state.endTime = myTarget.maxNeededTime;
                }

                UpdateStateTimeAfter(currentStateIndex);
            }
            else if (currentStateIndex + 1 == myTarget.StateOrder.Count)
            {
                state.endTime = myTarget.maxNeededTime;
                UpdateStateTimeBefore(currentStateIndex);
            }
            else if (currentStateIndex > 0 || currentStateIndex < myTarget.StateOrder.Count - 1)
            {
                UpdateStateTimeBefore(currentStateIndex);
                UpdateStateTimeAfter(currentStateIndex);
            }
            EditorUtility.SetDirty(myTarget);
        }
    }