Beispiel #1
0
        // After all objects are initialized, Awake is called when the script
        // is being loaded. This occurs before any Start calls.
        // Use Awake instead of the constructor for initialization.
        public void Awake()
        {
            motor = GetComponent <Motor>();
            if (motor == null)
            {
                Debug.Log("No Motor");
            }
            motor.AddSteeringScript();
            steeringBehaviour = motor.steeringBehaviour;
            if (steeringBehaviour == null)
            {
                Debug.Log("No Steering behaviour");
            }

            GameObject mainCamera = GameObject.Find("Main Camera");

            if (mainCamera != null)
            {
                targetedCameras = mainCamera.GetComponents <TargetedCamera>();
            }

            rowsPerColumn = Mathf.Max(3, rowsPerColumn);
        }
Beispiel #2
0
        // This creates the GUI inside the window.
        // It requires the id of the window it's currently making GUI for.
        private void WindowFunction(int windowID)
        {
            // Draw any Controls inside the window here.

            if (steeringBehaviour == null)
            {
                Debug.Log("Getting Steering Behavior");
                steeringBehaviour = GetComponent <SteeringBehaviour>();
            }

            if (steeringBehaviour == null)
            {
                Debug.Log("No Steering Behavior");
                return;
            }

            if (motor == null)
            {
                Debug.Log("Getting Motor");
                motor = GetComponent <Motor>();
            }

            if (motor == null)
            {
                Debug.Log("No Motor");
                return;
            }

            centeredLabelStyle ??= new GUIStyle(UnityEngine.GUI.skin.GetStyle("Label"))
            {
                alignment = TextAnchor.MiddleCenter
            };

            GUILayout.BeginHorizontal();

            GUILayout.Label(name, centeredLabelStyle);

            if (GUILayout.Button(motor.isAiControlled ? "is an AI" : "is a Player"))
            {
                motor.isAiControlled             = !motor.isAiControlled;
                steeringBehaviour.targetObject   = null;
                steeringBehaviour.targetPosition = transform.position;
            }

            if (targetedCameras != null && GUILayout.Button("Watch"))
            {
                foreach (TargetedCamera targetedCamera in targetedCameras)
                {
                    targetedCamera.target = transform;
                }
            }

            GUILayout.EndHorizontal();

            int targetIndex = 0;

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();

            if (GUILayout.Button("None"))
            {
                steeringBehaviour.targetObject   = null;
                steeringBehaviour.targetPosition = transform.position;
            }

            if (GUILayout.Button("Origin"))
            {
                steeringBehaviour.targetObject   = null;
                steeringBehaviour.targetPosition = Vector3.zero;
            }

            if (GUILayout.Button("Random"))
            {
                steeringBehaviour.targetObject   = null;
                steeringBehaviour.targetPosition = Random.insideUnitSphere * 50;
            }

            var row = 3;

            while (row < rowsPerColumn && targetIndex < targets.Length)
            {
                if (GUILayout.Button(targets[targetIndex].name))
                {
                    steeringBehaviour.targetObject = targets[targetIndex];
                }

                row++;
                targetIndex++;
            }

            GUILayout.EndVertical();

            while (targetIndex < targets.Length)
            {
                GUILayout.BeginVertical();

                row = 0;

                while (row < rowsPerColumn && targetIndex < targets.Length)
                {
                    if (GUILayout.Button(targets[targetIndex].name))
                    {
                        steeringBehaviour.targetObject = targets[targetIndex];
                    }

                    row++;
                    targetIndex++;
                }

                GUILayout.EndVertical();
            }

            GUILayout.EndHorizontal();

            // Make the windows be draggable.
            UnityEngine.GUI.DragWindow();
        }