void breakWindows()
    {
        if (Time.realtimeSinceStartup - timer > 8 && brokenWindowCount < 4)
        {
            if (Time.realtimeSinceStartup - timer > 8.2)
            {
                timer = Time.realtimeSinceStartup;
                return;
            }

            bool found = false;
            while (!found)
            {
                int randNum = Mathf.RoundToInt(Random.Range(0, 8));
                //Debug.Log(randNum);
                script = windowArray[randNum].GetComponent <WindowScript>();
                if ((gameObject.CompareTag("Water1") && script.roomId == 1) ||
                    (gameObject.CompareTag("Water2") && script.roomId == 2))
                {
                    if (script.isFixed)
                    {
                        script.isFixed = false;
                        found          = true;
                        timer          = Time.realtimeSinceStartup;
                        Debug.Log("Window broken");
                    }
                    else
                    {
                        //Debug.Log("no");
                    }
                }
            }
        }
    }
    protected string WindowCommand(string input, out bool success)
    {
        success = false;

        int windowIndx;

        if (!int.TryParse(input, out windowIndx))
        {
            return("'" + input + "' invalid number format");
        }

        // XXX: until i decide how to handle windows
        windowIndx = 0;

        WindowScript window = windows[windowIndx];

        if (window != null)
        {
            windows.RemoveAt(windowIndx);
            GameObject.Destroy(window.gameObject);
        }
        else
        {
            CreateWindow(-0.25f, 0.25f);
        }

        success = true;
        return("Window");
    }
Beispiel #3
0
    void Awake()
    {
        WS  = GameObject.FindGameObjectWithTag("WindowController").GetComponent <WindowScript> ();
        GCS = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameControllerScript> ();

        spriteRenderer        = GetComponent <SpriteRenderer>();
        spriteRenderer.sprite = fire1;
    }
Beispiel #4
0
    /// <summary>
    /// Instantiate the window instance.
    /// </summary>
    /// <returns>The window.</returns>
    /// <param name="prefab">Prefab.</param>
    public WindowScript ShowWindow(GameObject prefab)
    {
        WindowScript window = Utilities.CreateInstance(prefab, this.WindowsContainer, true).GetComponent <WindowScript>();

        window.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        this._windowInstances.Add(window);
        return(window);
    }
 //Sets the opened window as an active window.
 public void OpenWindow(WindowScript openWindow)
 {
     if (activeWindow != null)
     {
         activeWindow.activeWindow = false;
     }
     activeWindow = openWindow;
     SetActiveWindow(openWindow);
 }
 //Sets the window activity and it's title bar colours.
 public void SetActiveWindow(WindowScript openWindow)
 {
     if (activeWindow != null)
     {
         activeWindow.activeWindow = false;
         activeWindow.SetWindowActivity();
     }
     activeWindow = openWindow;
     activeWindow.activeWindow = true;
     activeWindow.SetWindowActivity();
 }
Beispiel #7
0
    public void OnPointerClick(PointerEventData eventData) //sets the set of the window to active.
    {
        WindowScript windowScript = window.GetComponent <WindowScript>();

        window.transform.SetAsLastSibling();
        themeManager.SetActiveWindow(windowScript);
        if (windowScript.minimised)
        {
            window.SetActive(true);
            windowScript.minimised = false;
        }
    }
    public void breakWindows(int roomId)
    {
        brokenWindowCount = 0;

        windowArray = GameObject.FindGameObjectsWithTag("Window");

        for (int i = 0; i < windowArray.Length; i++)
        {
            script = windowArray[i].GetComponent <WindowScript>();
            if ((roomId == 1 && script.roomId == 2) ||
                (roomId == 2 && script.roomId == 1)) // swapped for destroying windows in the other room
            {
                if (!script.isFixed)
                {
                    brokenWindowCount++;
                }
            }
        }

        if (brokenWindowCount < 4)
        {
            /*if (Time.realtimeSinceStartup - timer > 5.2)
             * {
             *  timer = Time.realtimeSinceStartup;
             *  return 0;
             * }*/

            bool found = false;
            while (!found)
            {
                int randNum = Mathf.RoundToInt(Random.Range(0, 8));
                //Debug.Log(randNum);
                script = windowArray[randNum].GetComponent <WindowScript>();
                if ((roomId == 1 && script.roomId == 2) ||
                    (roomId == 2 && script.roomId == 1))
                {
                    if (script.isFixed)
                    {
                        script.isFixed = false;
                        found          = true;
                        Debug.Log("Window broken");
                    }
                    else
                    {
                        //Debug.Log("no");
                    }
                }
            }
        }
    }
    protected int CreateWindow(Vector2 pos)
    {
        GameObject window = GameObject.Instantiate(windowPrefab) as GameObject;

        window.transform.SetParent(player.transform, false);

        RectTransform playerRect = player.GetComponent <RectTransform>();
        RectTransform windowRect = window.GetComponent <RectTransform>();

        windowRect.anchoredPosition = new Vector3(playerRect.rect.width * pos[0], playerRect.rect.height * pos[1], 0);

        WindowScript script = window.GetComponent <WindowScript>();

        windows.Add(script);

        return(windows.Count - 1);
    }
    void Start()
    {
        //Sets the variables
        windowScript      = GetComponentInParent <WindowScript>();
        draggingTransform = windowScript.GetComponent <RectTransform>();
        canvas            = ThemeManager.instance.ui;
        titleBarImage     = GetComponent <Image>();

        //Sets the colour of the titlebar to the active colour.
        titleBarImage.color = ThemeManager.instance.activeTitleBarColour;
        if (ThemeManager.instance.activeTitleBarColour.r <= 0.5f && ThemeManager.instance.activeTitleBarColour.g <= 0.5f && ThemeManager.instance.activeTitleBarColour.b <= 0.5f)
        {
            GetComponentInChildren <Text>().color = Color.white;
        }
        else
        {
            GetComponentInChildren <Text>().color = Color.black;
        }
    }
    void OnTriggerStay(Collider other)
    {
        //Debug.Log("Plank: " + plankCount + ", ladder: " + ladderCount);

        if (!canMove)
        {
            anim.Play("Repair");
            return;
        }

        if (other.tag == "Button" && !pressingButton)
        {
            bScript         = other.gameObject.GetComponent <ButtonScript>();
            bScript.pressed = true;
        }

        if ((playerId == 1 && Input.GetKeyDown("space")) || (playerId == 2 && Input.GetKeyDown(KeyCode.RightShift)))
        {
            if (other.tag == "LadderTrigger" && plankCount > 0)
            {
                canMove          = false;
                interactionStart = Time.realtimeSinceStartup;
                buildingLadder   = true;
                Debug.Log("Started using plank for ladder");
            }
            else if (other.tag == "Window") // and window is broken
            {
                script = other.gameObject.GetComponent <WindowScript>();
                if (!script.isFixed)
                {
                    canMove          = false;
                    interactionStart = Time.realtimeSinceStartup;
                    fixingWindow     = true;
                    Debug.Log("Started fixing window");
                }
                else
                {
                    Debug.Log("Window is already fixed");
                }
            }
        }
    }
    void Start()
    {
        // Console
        console = gameObject.transform.Find("Console").GetComponent <WindowScript>();
        if (!console)
        {
            Debug.LogError("Player could not find Console");
        }
        consoleText = console.transform.Find("TextScroll/TextField").GetComponent <Text>() as Text;
        if (!consoleText)
        {
            Debug.LogError("Console did not find TextField!");
        }
        inputField = console.transform.Find("InputField").GetComponent <InputField>() as InputField;
        if (!inputField)
        {
            Debug.LogError("Console did not find InputField!");
        }
        else
        {
            inputField.onEndEdit.AddListener(delegate(string input) {
                if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                {
                    if (inputField.text.Length > 0)
                    {
                        OnInputSubmit(input);
                        anyKeyLatch = true;
                    }
                }
            });
        }

        ShowRender(isVisible);

        // Focus input field
        if (isVisible)
        {
            SelectInputField();
        }
    }
Beispiel #13
0
    void Start() //This sets all the variables.
    {
        transform.SetParent(GameObject.Find("TaskbarObjects").transform);

        WindowScript windowScript = window.GetComponent <WindowScript>();

        taskbarImage = transform.GetChild(1).GetComponentInChildren <Image>();
        taskbarText  = GetComponentInChildren <Text>();

        GetComponent <Image>().color = themeManager.TaskbarColour;
        if (GetComponent <Image>().color.r <= 0.5f && GetComponent <Image>().color.g <= 0.5f && GetComponent <Image>().color.b <= 0.5f)
        {
            GetComponentInChildren <Text>().color = Color.white;
        }
        else
        {
            GetComponentInChildren <Text>().color = Color.black;
        }

        taskbarImage.sprite = windowScript.titleBarIcon.sprite;
        taskbarText.text    = windowScript.titleBarText.text;
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        brokenWindowCount = 0;

        windowArray = GameObject.FindGameObjectsWithTag("Window");

        for (int i = 0; i < windowArray.Length; i++)
        {
            script = windowArray[i].GetComponent <WindowScript>();
            if ((gameObject.CompareTag("Water1") && script.roomId == 1) ||
                (gameObject.CompareTag("Water2") && script.roomId == 2))
            {
                if (!script.isFixed)
                {
                    brokenWindowCount++;
                }
            }
        }
        //Debug.Log(brokenWindowCount);

        breakWindows();

        waterSpeedModifier = (float)(brokenWindowCount / 1.0);

        if (transform.position.y < 9)
        {
            if (brokenWindowCount == 0)
            {
                transform.position += Vector3.up * 0.001f;
            }
            else
            {
                transform.position += Vector3.up * 0.003f * waterSpeedModifier;
            }
        }
    }
Beispiel #15
0
    private void OnGUI()
    {
        //Window Scene
        GUILayout.Label("Window", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Title Bar Sprite:");
        windowSprite = (Sprite)EditorGUILayout.ObjectField(windowSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window Name:");
        windowName = EditorGUILayout.TextField("", windowName);
        EditorGUILayout.EndHorizontal();

        windowSize = EditorGUILayout.Vector2Field("Window Size: ", windowSize);

        EditorGUILayout.Space();

        if (GUILayout.Button("Create Window"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (windowSprite == null)
            {
                Debug.LogWarning("Window Sprite cannot contain an empty field");
            }
            else if (windowName == null)
            {
                Debug.LogWarning("Window Name cannot contain an empty field");
            }
            else
            {
                string path = "Assets/Prefabs/Windows/" + windowName + ".prefab";
                path = AssetDatabase.GenerateUniqueAssetPath(path);

                GameObject tmpWindow = Instantiate(windowPrefab);

                tmpWindow.GetComponent <RectTransform>().sizeDelta = new Vector2(windowSize.x + 4, windowSize.y + 4);
                WindowScript windowScript = tmpWindow.GetComponent <WindowScript>();
                windowScript.titleBarIcon.sprite = windowSprite;
                windowScript.titleBarText.text   = windowName;

                PrefabUtility.SaveAsPrefabAsset(tmpWindow, path);

                Destroy(tmpWindow);

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = windowPrefab;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();

        //Icon Settings
        GUILayout.Label("Icon", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        iconSprite = (Sprite)EditorGUILayout.ObjectField(iconSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        iconString = EditorGUILayout.TextField("", iconString);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window:");
        iconWindow = (GameObject)EditorGUILayout.ObjectField(iconWindow, typeof(GameObject), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Create Icon"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (iconSprite == null)
            {
                Debug.LogWarning("Icon Sprite cannot contain an empty field");
            }
            else if (iconString == null)
            {
                Debug.LogWarning("Icon Name cannot contain an empty field");
            }
            else if (iconWindow == null)
            {
                Debug.LogWarning("Window cannot contain an empty field, create one if you need to.");
            }
            else
            {
                Icon iconScriptableObject = CreateInstance <Icon>();
                iconScriptableObject.iconName   = iconString;
                iconScriptableObject.iconSprite = iconSprite;
                iconScriptableObject.window     = iconWindow;

                AssetDatabase.CreateAsset(iconScriptableObject, "Assets/ScriptableObjects/Icons/" + iconString + ".asset");
                AssetDatabase.SaveAssets();

                GameObject tmpIcon    = Instantiate(iconPrefab);
                IconScript iconScript = tmpIcon.GetComponent <IconScript>();
                iconScript.icon             = iconScriptableObject;
                iconScript.transform.parent = ThemeManager.instance.iconSpace.transform;

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = iconScriptableObject;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();

        //Start Menu Item Settings
        GUILayout.Label("Start Menu Item", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        itemSprite = (Sprite)EditorGUILayout.ObjectField(itemSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        itemName = EditorGUILayout.TextField("", itemName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window:");
        itemWindow = (GameObject)EditorGUILayout.ObjectField(itemWindow, typeof(GameObject), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        putOnStartMenu = EditorGUILayout.Toggle("Add to start menu?", putOnStartMenu);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        if (GUILayout.Button("Create Start Menu Button"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (itemSprite == null)
            {
                Debug.LogWarning("Item Sprite cannot contain an empty field");
            }
            else if (itemName == null)
            {
                Debug.LogWarning("Item Name cannot contain an empty field");
            }
            else if (itemWindow == null)
            {
                Debug.LogWarning("Window cannot contain an empty field, create one if you need to.");
            }
            else
            {
                StartMenuItem itemScriptableObject = CreateInstance <StartMenuItem>();
                itemScriptableObject.menuName = itemName;
                itemScriptableObject.sprite   = itemSprite;
                itemScriptableObject.window   = itemWindow;

                AssetDatabase.CreateAsset(itemScriptableObject, "Assets/ScriptableObjects/Start Menu Items/" + itemName + ".asset");
                AssetDatabase.SaveAssets();

                if (putOnStartMenu)
                {
                    StartMenuScript startMenu = ThemeManager.instance.taskbarCanvas.GetComponentInChildren <StartMenuScript>();
                    startMenu.startMenuItems.Add(itemScriptableObject);
                }

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = itemScriptableObject;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();
        //Notification Settings
        GUILayout.Label("Create a new Notification", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        NotificationSprite = (Sprite)EditorGUILayout.ObjectField(NotificationSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        notificationName = EditorGUILayout.TextField("", notificationName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Lifespan:");
        notificationLifespan = EditorGUILayout.FloatField(notificationLifespan);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Tooltip Text:");
        notificationToolTip = EditorGUILayout.TextField("", notificationToolTip);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        notificationPopupDespawn = EditorGUILayout.Toggle("Despawn?", notificationPopupDespawn);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        GUILayout.Label("Popup Settings", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Lifespan:");
        notificationPopupLifespan = EditorGUILayout.FloatField(notificationPopupLifespan);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Title:");
        notificationPopupTitle = EditorGUILayout.TextField("", notificationPopupTitle);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Description:");
        notificationPopupDescription = EditorGUILayout.TextField("", notificationPopupDescription);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Create Notification"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (NotificationSprite == null)
            {
                Debug.LogWarning("Notification Sprite cannot contain an empty field");
            }
            else if (notificationName == null)
            {
                Debug.LogWarning("Notification Name cannot contain an empty field");
            }
            else if (notificationToolTip == null)
            {
                Debug.LogWarning("Tooltip cannot contain an empty field");
            }
            else if (notificationPopupLifespan <= 0)
            {
                Debug.LogWarning("The popup needs to have a lifespan, or to be put on permamently.");
            }
            else if (notificationLifespan <= 0 && !notificationPopupDespawn)
            {
                Debug.LogWarning("Lifespan needs to be greater than 0 or to be on permamently.");
            }
            else if (notificationPopupTitle == null)
            {
                Debug.LogWarning("Notification Popup Title cannot be an empty field");
            }
            else if (notificationPopupDescription == null)
            {
                Debug.LogWarning("Notification Description cannot be an empty field");
            }
            else
            {
                Notification notification = CreateInstance <Notification>();

                notification.notificationSprite      = NotificationSprite;
                notification.notificationTitle       = notificationPopupTitle;
                notification.notificationToolTipText = notificationToolTip;
                notification.notificationText        = notificationPopupDescription;
                notification.stayOnPermamently       = notificationPopupDespawn;
                notification.notificationLifespan    = notificationPopupLifespan;

                AssetDatabase.CreateAsset(notification, "Assets/ScriptableObjects/Notifications/" + notificationName + ".asset");
                AssetDatabase.SaveAssets();

                GameObject      tmpNotif    = Instantiate(notificationPrefab);
                NotificationObj notifScript = tmpNotif.GetComponent <NotificationObj>();
                notifScript.notification     = notification;
                notifScript.transform.parent = ThemeManager.instance.taskbar.GetComponentInChildren <NotificationAreaScript>().NotificationsSpace.transform;

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = notification;
                Debug.Log(":)");
            }
        }
    }
Beispiel #16
0
        /// <summary>
        /// Handler for end drag event.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        public void OnEndDrag(PointerEventData eventData)
        {
            DebugEx.VerboseFormat("DockingTabButton.OnEndDrag(eventData = {0})", eventData);

            foreach (DockingAreaScript dockingArea in mDockingAreas)
            {
                dockingArea.ClearDragInfo();
            }

            mDockingAreas = null;

            if (DummyDockWidgetScript.instance != null)
            {
                int index = DummyDockWidgetScript.instance.parent.children.IndexOf(DummyDockWidgetScript.instance);

                if (index >= 0)
                {
                    DummyDockWidgetScript.instance.parent.InsertDockWidget(DragInfoHolder.dockWidget, index);
                    DummyDockWidgetScript.instance.parent.selectedIndex = index;
                }
                else
                {
                    DebugEx.Fatal("Unexpected behaviour in DockingTabButton.OnEndDrag()");
                }

                DummyDockWidgetScript.DestroyInstance();
            }
            else
            if (DragInfoHolder.dockingArea == null)
            {
                WindowScript parentWindow = Utils.FindInParents <WindowScript>(gameObject);

                if (parentWindow != null)
                {
                    //***************************************************************************
                    // DockingWindow GameObject
                    //***************************************************************************
                    #region DockingWindow GameObject
                    GameObject dockingWindow = new GameObject("DockingWindow");
                    Utils.InitUIObject(dockingWindow, parentWindow.transform.parent);

                    //===========================================================================
                    // DockingWindowScript Component
                    //===========================================================================
                    #region DockingWindowScript Component
                    DockingWindowScript dockingWindowScript = dockingWindow.AddComponent <DockingWindowScript>();

                    dockingWindowScript.dockWidget = DragInfoHolder.dockWidget;

                    dockingWindowScript.x      = DragData.x - 8f;
                    dockingWindowScript.y      = DragData.y - 15f;      // - 8f      - 7f
                    dockingWindowScript.width  = DragData.width + 16f;  // + 8f + 8f
                    dockingWindowScript.height = DragData.height + 23f; // + 8f + 8f + 7f

                    dockingWindowScript.Show();
                    #endregion
                    #endregion
                }
                else
                {
                    DebugEx.Fatal("Unexpected behaviour in DockingTabButton.OnEndDrag()");
                }
            }

            DragInfoHolder.dockWidget    = null;
            DragInfoHolder.minimum       = float.MaxValue;
            DragInfoHolder.dockingArea   = null;
            DragInfoHolder.mouseLocation = DragInfoHolder.MouseLocation.Outside;

            DragData.EndDrag();
        }
Beispiel #17
0
 void Awake()
 {
     windowScriptInstance = this;
 }
Beispiel #18
0
 private void OnMouseDrag()
 {
     commandDragObject(WindowScript.GetMouseToWorldPoint(), offset);
     return;
 }
Beispiel #19
0
 private void OnMouseDown()
 {
     offset = WindowScript.CalculateOffset(WindowScript.GetMouseToWorldPoint(), thisTransform.position);
     return;
 }