Esempio n. 1
0
    public SquadTrigger CreateSquadTrigger()
    {
        GameObject squadTriggerObject = new GameObject();

        squadTriggerObject.transform.parent = transform;
        squadTriggerObject.AddComponent <BoxCollider>();
        squadTriggerObject.AddComponent <SquadTrigger>();

        SquadTrigger squadTrigger = squadTriggerObject.GetComponent <SquadTrigger>();

        squadTrigger.SquadManager = this;
        squadTrigger.Squads       = new List <Squad>();

        float zScale  = spawnAreaObject.transform.localScale.z;
        float zOffset = 0.0f;

        foreach (SquadTrigger refSquadTrigger in SquadTriggers)
        {
            if (refSquadTrigger.transform.position.z > zOffset)
            {
                zOffset = refSquadTrigger.transform.position.z;
            }
        }

        squadTriggerObject.transform.position = new Vector3(transform.position.x, transform.position.y, zOffset + zScale);

        squadTriggerObject.transform.localScale = spawnAreaObject.transform.localScale;

        return(squadTrigger);
    }
Esempio n. 2
0
 //Remove last squad in the list
 public void RemoveSquadAtEnd(SquadTrigger squadTrigger)
 {
     if (squadTrigger.Squads.Count > 0)
     {
         RemoveSquad(squadTrigger.Squads[squadTrigger.Squads.Count - 1]);
     }
 }
Esempio n. 3
0
    //Add a new squad to the manager after another squad in the list
    public Squad AddSquadAfter(Squad referenceSquad)
    {
        SquadTrigger squadTrigger = referenceSquad.SquadTrigger;

        //Iterate through array of squad objects
        for (int i = 0; i < squadTrigger.Squads.Count; i++)
        {
            //If iterated object is the same as the reference object passed in
            if (squadTrigger.Squads[i].GetInstanceID() == referenceSquad.GetInstanceID())
            {
                //Create new child object, attach Squad script and set it's Squad Manager to this
                Squad squad = CreateSquad(squadTrigger);

                //Insert new object at position after reference object
                squadTrigger.Squads.Insert(i + 1, squad);

                //Update names to ensure list makes sense
                UpdateNames();

                return(squad);
            }
        }

        return(null);
    }
Esempio n. 4
0
    public void AddSquadTriggerAtEnd()
    {
        SquadTrigger squadTrigger = CreateSquadTrigger();

        squadTriggers.Add(squadTrigger);

        UpdateNames();
    }
Esempio n. 5
0
    //Add a new squad to the manager at end
    public void AddSquadAtEnd(SquadTrigger squadTrigger)
    {
        Squad squad = CreateSquad(squadTrigger);

        squadTrigger.Squads.Add(squad);

        //Update names to ensure list makes sense
        UpdateNames();
    }
 public static void ShowOtherSquadBoundaries(SquadTrigger referenceSquadTrigger)
 {
     foreach (SquadTrigger squadTrigger in referenceSquadTrigger.SquadManager.SquadTriggers)
     {
         if (squadTrigger.GetInstanceID() != referenceSquadTrigger.GetInstanceID())
         {
             ShowSquadBoundaries(squadTrigger);
         }
     }
 }
Esempio n. 7
0
    //Remove specific squad from list
    public void RemoveSquadTrigger(SquadTrigger squadTrigger)
    {
        //Remove squad object from list
        squadTriggers.Remove(squadTrigger);

        //Destroy the squad object and associated trigger
        DestroyImmediate(squadTrigger.gameObject);

        //Update names to ensure list makes sense
        UpdateNames();
    }
Esempio n. 8
0
    public Squad CreateSquad(SquadTrigger squadTrigger)
    {
        //Create new squad GameObject, add appropraite scripts and position
        GameObject squadObject = new GameObject();

        squadObject.AddComponent <Squad>();

        Squad squad = squadObject.GetComponent <Squad>();

        squadObject.transform.parent   = squadTrigger.transform;
        squadObject.transform.position = new Vector3(squadTrigger.transform.position.x, squadTrigger.transform.position.y, squadTrigger.transform.position.z + squadTrigger.Squads.Count + 1.0f);
        //Set the squad's trigger
        squad.SquadTrigger = squadTrigger;

        squad.SetPositions();

        return(squad);
    }
    //Projects the boundaries of the box collider tied to the squad trigger
    public static void ShowSquadBoundaries(SquadTrigger squadTrigger)
    {
        BoxCollider boxCollider = squadTrigger.GetComponent <BoxCollider>();

        Handles.color = Color.green;
        float lineSize = 1.0f;

        Vector3[] boundaryCorners = new Vector3[8];

        boundaryCorners[0] = boxCollider.bounds.min;                                                                    //Bottom Left
        boundaryCorners[1] = new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.max.y, boxCollider.bounds.min.z); //Top Left
        boundaryCorners[2] = new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.max.y, boxCollider.bounds.min.z); //Top Right
        boundaryCorners[3] = new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.min.y, boxCollider.bounds.min.z); //Bottom Right

        boundaryCorners[4] = new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.min.y, boxCollider.bounds.max.z); //Bottom Left
        boundaryCorners[5] = new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.max.y, boxCollider.bounds.max.z); //Top Left
        boundaryCorners[6] = boxCollider.bounds.max;                                                                    //Top Right
        boundaryCorners[7] = new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.min.y, boxCollider.bounds.max.z); //Bottom Right


        //Draw front square
        Handles.DrawDottedLine(boundaryCorners[0], boundaryCorners[1], lineSize);
        Handles.DrawDottedLine(boundaryCorners[1], boundaryCorners[2], lineSize);
        Handles.DrawDottedLine(boundaryCorners[2], boundaryCorners[3], lineSize);
        Handles.DrawDottedLine(boundaryCorners[3], boundaryCorners[0], lineSize);

        //Draw back square
        Handles.DrawDottedLine(boundaryCorners[4], boundaryCorners[5], lineSize);
        Handles.DrawDottedLine(boundaryCorners[5], boundaryCorners[6], lineSize);
        Handles.DrawDottedLine(boundaryCorners[6], boundaryCorners[7], lineSize);
        Handles.DrawDottedLine(boundaryCorners[7], boundaryCorners[4], lineSize);

        //Draw side lines
        Handles.DrawDottedLine(boundaryCorners[0], boundaryCorners[4], lineSize);
        Handles.DrawDottedLine(boundaryCorners[1], boundaryCorners[5], lineSize);
        Handles.DrawDottedLine(boundaryCorners[2], boundaryCorners[6], lineSize);
        Handles.DrawDottedLine(boundaryCorners[3], boundaryCorners[7], lineSize);
    }
    //Projects spawn-markers (Handles) with selected settings
    public static void ShowSpawnMarkers(SquadTrigger squadTrigger)
    {
        foreach (Squad squad in squadTrigger.Squads)
        {
            if (squad.UnitPositions != null)
            {
                for (int count = 0; count < squad.UnitPositions.Length; count++)
                {
                    if (count == 0)
                    {
                        Handles.color = Color.red;

                        //Spawn button marker at location of squad
                        if (Handles.Button(squad.UnitPositions[count], Quaternion.identity, 0.25f, 0.25f, Handles.DotCap))
                        {
                            //Make squad active GameObject in Hierarchy
                            Selection.activeGameObject = squad.gameObject;
                        }
                    }
                    else
                    {
                        Handles.color = Color.yellow;

                        //Spawn simple marker at target Vector
                        if (Handles.Button(squad.UnitPositions[count], Quaternion.identity, 0.25f, 0.25f, Handles.DotCap))
                        {
                            UnitCursor cursor = squadTrigger.SquadManager.UnitCursor.GetComponent <UnitCursor>();

                            cursor.SetUnit(count, squad);

                            Selection.activeGameObject = cursor.gameObject;
                        }
                    }
                }
            }
        }
    }
Esempio n. 11
0
    public override void OnInspectorGUI()
    {
        if (serializedObject.targetObject)
        {
            serializedObject.Update();

            EditorGUILayout.Separator();

            squadManager.spawnAreaObject = (GameObject)EditorGUILayout.ObjectField("Spawn Area: ", squadManager.spawnAreaObject, typeof(GameObject), true);

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            if (squadManager.spawnAreaObject)
            {
                squadManager.alignSquadTriggers = EditorGUILayout.Toggle("Align Squads on Z-Axis", squadManager.alignSquadTriggers);

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                //Create buttons for adding and removing squad triggers
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("(-) Remove Squad Trigger At End"))
                {
                    if (squadManager.SquadTriggers.Count > 0)
                    {
                        squadManager.RemoveSquadTriggerAtEnd();
                    }
                }

                if (GUILayout.Button("(+) Add Squad Trigger At End"))
                {
                    squadManager.AddSquadTriggerAtEnd();
                }
                EditorGUILayout.EndHorizontal();


                //If there are squad triggers to display
                if (squadManager.SquadTriggers.Count > 0)
                {
                    //Iterate through the list of squad triggers
                    for (int i = 0; i < squadManager.SquadTriggers.Count; i++)
                    {
                        EditorGUILayout.Separator();
                        EditorGUILayout.Separator();
                        EditorGUILayout.Separator();

                        SquadTrigger squadTrigger = squadManager.SquadTriggers[i];

                        if (squadTrigger)
                        {
                            if (GUILayout.Button(squadTrigger.name))
                            {
                                //Make squad trigger active GameObject in Hierarchy
                                Selection.activeGameObject = squadTrigger.gameObject;
                            }

                            //Create buttons for adding Squad Trigger After/Before and Removing a Squad Trigger
                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Button("(-) Remove This Squad Trigger", EditorStyles.miniButton))
                            {
                                squadManager.RemoveSquadTrigger(squadTrigger);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }

                if (squadManager)
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
    }
Esempio n. 12
0
 public void OnEnable()
 {
     squadTrigger = (SquadTrigger)target;
 }