예제 #1
0
        private void SelectState(TSSState state)
        {
            if (Application.isPlaying)
            {
                if (core.currentState == state)
                {
                    core.Close(state);
                    return;
                }

                core.SelectState(state);
                return;
            }

            if (core.currentState == state)
            {
                state.ActivateManualy(ActivationMode.closeBranchImmediately);
                core.currentState = null;
            }
            else
            {
                for (int i = 0; i < core.Count; i++)
                {
                    core[i].ActivateManualy(state == core[i]
                        ? ActivationMode.openBranchImmediately
                        : ActivationMode.closeBranchImmediately);

                    core.currentState = state;
                }
            }
        }
예제 #2
0
    // Use this for initialization
    void Awake()
    {
        // Add "TSS Core" component
        TSSCore core = this.gameObject.AddComponent <TSSCore>();

        // Clone state object and additing clone to core as new state
        for (int i = 0; i < stateCount; i++)
        {
            // Clone state or use first
            TSSItem newStateObject = i == 0 ?
                                     stateObject :
                                     Instantiate(stateObject.gameObject, this.transform).GetComponent <TSSItem>();

            // Mark state text by index
            Text stateText = newStateObject.GetComponentInChildren <Text>();
            stateText.text = (i + 1).ToString();

            // Add state and selecting key
            TSSState stateState = core.AddState(newStateObject, (i + 1).ToString());
            stateState.AddSelectionKey((KeyCode)((int)KeyCode.Alpha1 + i));
        }

        // Set first core state as default. Default state will be selected and activated on start.
        // You can use any of syntax:
        // core.SetDefaultState(core.GetState("0"));
        // core.SetDefaultState("0");
        // core.SetDefaultState(core[0]);
        core[0].SetAsDefault();

        // Allow core events
        core.useEvents = true;

        // Update navigation buttons interactable by core events
        core.OnStateSelected.AddListener(state =>
        {
            prevBtn.interactable = !state.isFirst;
            nextBrn.interactable = !state.isLast;
        });

        // Attach core selecting method to buttons
        nextBrn.onClick.AddListener(core.SelectNextState);
        prevBtn.onClick.AddListener(core.SelectPreviousState);

        // Select core state
        // You can use any of syntax:
        // core.SelectState(core.GetState(0).ToString()));
        // core.SelectState("0");
        // core.GetState((currentStateID + 1).ToString()).Select();
        core[0].Select();
    }
예제 #3
0
 private bool DrawStateDeleteButton(TSSState state)
 {
     if (!GUILayout.Button(delStateButtonContent, TSSEditorUtils.max18pxWidth, TSSEditorUtils.fixedLineHeight))
     {
         return(false);
     }
     if (!EditorUtility.DisplayDialog(confirmRemoveTitle.text, string.Format(confirmRemoveMessage.text, state.name), "Yes", "No"))
     {
         return(false);
     }
     Undo.RecordObject(core, "[TSS Core] remove state");
     core.RemoveState(state);
     return(true);
 }
예제 #4
0
        private void DrawStateItems(TSSState state)
        {
            EditorGUILayout.BeginHorizontal();

            if (state.overrideModes)
            {
                EditorGUILayout.LabelField(propertyItem, TSSEditorUtils.max120pxWidth);

                TSSEditorUtils.DrawGenericProperty(ref state.modeOpenOverride, TSSEditorUtils.greenColor, core);
                TSSEditorUtils.DrawGenericProperty(ref state.modeCloseOverride, TSSEditorUtils.redColor, core);
            }
            else
            {
                EditorGUILayout.LabelField(propertyItem);
            }

            TSSEditorUtils.DrawGenericProperty(ref state.overrideModes, core);

            if (GUILayout.Button(addItemButtonContent, TSSEditorUtils.max18pxWidth, TSSEditorUtils.fixedLineHeight))
            {
                Undo.RecordObject(core, "[TSS Core] add new item");
                state.AddItem(null);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical();

            GUI.backgroundColor = Color.white;

            for (int i = 0; i < state.Count; i++)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                EditorGUILayout.BeginHorizontal();

                TSSEditorUtils.DrawGenericProperty(ref state[i].enabled, core);

                EditorGUI.BeginDisabledGroup(!state[i].enabled);

                TSSEditorUtils.DrawGenericProperty(ref state[i].item, core);

                if (state[i].item != null && !state.overrideModes)
                {
                    TSSEditorUtils.DrawGenericProperty(ref state[i].overrideModes, core);
                }

                EditorGUI.EndDisabledGroup();

                if (GUILayout.Button(delItemButtonContent, TSSEditorUtils.max18pxWidth, TSSEditorUtils.fixedLineHeight))
                {
                    Undo.RecordObject(core, "[TSS Core] remove item");
                    state.RemoveItem(i);
                    return;
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.BeginDisabledGroup(!state[i].enabled);

                EditorGUILayout.BeginHorizontal();
                if (!state.overrideModes && state[i].overrideModes && state[i].item != null)
                {
                    TSSEditorUtils.DrawGenericProperty(ref state[i].mode[1], TSSEditorUtils.greenColor, core);
                    TSSEditorUtils.DrawGenericProperty(ref state[i].mode[0], TSSEditorUtils.redColor, core);
                }
                EditorGUILayout.EndHorizontal();

                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
예제 #5
0
        private bool DrawState(TSSState state, int stateID)
        {
            if (state == null)
            {
                return(false);
            }

            EditorGUILayout.BeginVertical();

            TSSEditorUtils.BeginBlackVertical();

            EditorGUILayout.BeginHorizontal();

            bool isStateEnabled = state.enabled;

            TSSEditorUtils.DrawGenericProperty(ref isStateEnabled, core);
            if (core.currentState == state && state.enabled && !isStateEnabled)
            {
                if (Application.isPlaying)
                {
                    state.Close();
                }
                else
                {
                    state.ActivateManualy(ActivationMode.closeBranchImmediately);
                }
                core.currentState = null;
            }

            state.enabled = isStateEnabled;

            EditorGUI.BeginDisabledGroup(!state.enabled);

            state.editing = EditorGUILayout.Foldout(state.editing, string.Format("   {0} {1}", state.name, state == core.defaultState ? " (default)" : string.Empty), true, stateFoldAutStyle);

            if (state != core.defaultState && GUILayout.Button(stateSetDefault, TSSEditorUtils.max80pxWidth, TSSEditorUtils.fixedLineHeight))
            {
                Undo.RecordObject(core, "[TSS Core] default state");
                core.SetDefaultState(state);
            }

            else if (state == core.defaultState && GUILayout.Button(stateUnsetDefault, TSSEditorUtils.max80pxWidth, TSSEditorUtils.fixedLineHeight))
            {
                Undo.RecordObject(core, "[TSS Core] default state");
                core.SetDefaultState();
            }

            if (core.currentState == state)
            {
                GUI.color = TSSEditorUtils.greenColor;
            }

            if (GUILayout.Button(stateSelect, TSSEditorUtils.max50pxWidth, TSSEditorUtils.fixedLineHeight))
            {
                SelectState(state);
            }

            GUI.color = Color.white;

            EditorGUI.EndDisabledGroup();

            if (DrawStateDeleteButton(state))
            {
                return(false);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(!state.enabled);

            if (state.editing)
            {
                TSSEditorUtils.DrawGenericProperty(ref state.name, "State Name", core);

                TSSEditorUtils.DrawSeparator();
                DrawStateItems(state);

                TSSEditorUtils.DrawSeparator();
                TSSEditorUtils.DrawEventProperty(statesProperty.GetArrayElementAtIndex(stateID), "onOpen", state.onOpen.GetPersistentEventCount());
                GUILayout.Space(3);
                TSSEditorUtils.DrawEventProperty(statesProperty.GetArrayElementAtIndex(stateID), "onClose", state.onClose.GetPersistentEventCount());

                if (core.useInput)
                {
                    TSSEditorUtils.DrawSeparator();
                    TSSEditorUtils.DrawKeyCodeListProperty(state.onKeyboard, core, statesProperty.GetArrayElementAtIndex(stateID).FindPropertyRelative("onKeyboard"), false);
                }
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();
            GUILayout.Space(3);

            return(true);
        }
예제 #6
0
파일: LoaderMap.cs 프로젝트: Rover47/Kama
    IEnumerator LoadContent()
    {
        GameObject emptyGO      = new GameObject();
        string     pathToFolder = Path.Combine(Application.streamingAssetsPath, _pathFromStreamingFolder);

        string[] dirs = Directory.GetDirectories(pathToFolder);

        string pathToFile = Path.Combine(dirs[0], "size.txt");

        if (!File.Exists(pathToFile))
        {
            Debug.LogError("Size file not found!!!");
        }

        string[] vextorSize = File.ReadAllLines(pathToFile);
        float.TryParse(vextorSize[0], out _sizeImage.x);
        float.TryParse(vextorSize[1], out _sizeImage.y);
        int.TryParse(vextorSize[2], out _countArrayWidth);
        int.TryParse(vextorSize[3], out _countArrayHeight);

        _groupMinimap.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _sizeImage.x);
        _groupMinimap.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _sizeImage.y);

        RectTransform container = _contentTransform.GetComponent <RectTransform>();

        container.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _sizeImage.x);
        container.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _sizeImage.y);

        TSSCore core = GetComponent <TSSCore>();

        _directAlphaProfile = Resources.Load <TSSProfile>("DirectAlpha");
        bool lastFlag;

        for (int j = 0; j < dirs.Length; j++)
        {
            functionLoadForAttach(dirs[j]);

            List <string> currentListImage = _attachFiles;
            int           currentArrayWidth = 0, currentArrayHeight = 0;
            lastFlag = j == dirs.Length - 1 ? true : false;

            GameObject groupObject = Instantiate(emptyGO, _contentTransform.transform);
            groupObject.name = j == 0 ? "Map" : groupObject.name = "Prep_" + j.ToString("00");
            groupObject.AddComponent <RectTransform>();
            groupObject.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _sizeImage.x);
            groupObject.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _sizeImage.y);

            if (j == 0)
            {
                TSSItem  newStateObject = new TSSItem();
                TSSState stateState     = core.AddState(newStateObject, (j).ToString());
                stateState.AddSelectionKey((KeyCode)((int)KeyCode.Alpha0));
            }
            else
            {
                groupObject.AddComponent <CanvasGroup>();
                TSSItem  newStateObject = groupObject.AddComponent <TSSItem>();
                TSSState stateState     = core.AddState(newStateObject, (j).ToString());
                stateState.AddSelectionKey((KeyCode)((int)KeyCode.Alpha1 + j - 1));
                newStateObject.profile = _directAlphaProfile;

                TSSProfile.ProfileRevert(newStateObject, _directAlphaProfile);
            }

            foreach (var element in currentListImage)
            {
                using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(element))
                {
                    yield return(uwr.SendWebRequest());

                    if (uwr.isNetworkError || uwr.isHttpError)
                    {
                        Debug.Log(uwr.error);
                    }
                    else
                    {
                        var texture = DownloadHandlerTexture.GetContent(uwr);
                        texture.Compress(true);
                        texture.Apply(false, true);

                        GameObject _currentMapElement = Instantiate(_prefabElementMap, groupObject.transform);
                        _currentMapElement.GetComponent <RawImage>().texture = texture;
                        _currentMapElement.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, texture.width);
                        _currentMapElement.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, texture.height);
                        _currentMapElement.GetComponent <RectTransform>().anchoredPosition = new Vector2(currentArrayWidth * 8000, currentArrayHeight * -8000);

                        currentArrayWidth++;
                        if (currentArrayWidth >= _countArrayWidth)
                        {
                            currentArrayHeight++;
                            currentArrayWidth = 0;
                        }
                    }
                    uwr.Dispose();
                    yield return(new WaitForSeconds(0.1f));
                }
            }
            if (lastFlag)
            {
                CreateMinimap();
            }
        }

        core.useEvents = true;
        TSS.Base.TSSBehaviour.RefreshAndStart();
        Destroy(emptyGO);
        _flagLoad = true;
    }