Exemple #1
0
    void Update()
    {
        if (perHpNotch <= 0)
        {
            perHpNotch = 1;
        }

        requiredNotches = Mathf.FloorToInt((float)energyGaugeUI.max / (float)perHpNotch);

        if (requiredNotches > energyGaugeUI.barSets.Count)
        {
            energyGaugeUI.AddNotch();
        }
        else if (requiredNotches < energyGaugeUI.barSets.Count)
        {
            energyGaugeUI.RemoveNotch();
        }
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        myTarget = (EnergyGaugeUI)target;
        SerializedObject serializedObject = new SerializedObject(target);

        SerializedProperty serializedProperty_current = serializedObject.FindProperty("current");
        SerializedProperty serializedProperty_max     = serializedObject.FindProperty("max");

        EditorGUI.BeginChangeCheck();
        showDebug = GUILayout.Toggle(showDebug, "show debug");
        if (EditorGUI.EndChangeCheck())
        {
            HideGos(showDebug);
        }
        GUILayout.Space(20);
        GUILayout.BeginHorizontal();

        EditorGUI.BeginChangeCheck();
        int preCurrent = serializedProperty_current.intValue;

        preCurrent = EditorGUILayout.IntSlider(preCurrent, 0, serializedProperty_max.intValue);

        if (EditorGUI.EndChangeCheck())
        {
            serializedProperty_current.intValue = preCurrent;
        }

        //call this if inspector changed

        CheckUpdates();
        myTarget.MainGauge();
        myTarget.RequiredGauge();



        //serializedProperty_current.intValue = preCurrent;
        EditorGUILayout.LabelField(" / " + serializedProperty_max.intValue, GUILayout.Width(80));
        GUILayout.EndHorizontal();


        SerializedProperty barSets_p = serializedObject.FindProperty("barSets");

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("+ Notch"))
        {
            if (Application.isPlaying)
            {
                myTarget.AddNotch();
            }
            else
            {
                //clear new notch
                serializedObject.Update();
                barSets_p.InsertArrayElementAtIndex(barSets_p.arraySize);

                int id = barSets_p.arraySize - 1;
                SerializedProperty mask_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("mask");
                mask_p.objectReferenceValue = null;
                SerializedProperty img_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("img");
                img_p.objectReferenceValue = null;
                SerializedProperty requiredImg_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("requiredImg");
                requiredImg_p.objectReferenceValue = null;
                SerializedProperty requiredMask_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("requiredMask");
                requiredMask_p.objectReferenceValue = null;
                SerializedProperty bleedImg_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("bleedImg");
                bleedImg_p.objectReferenceValue = null;

                serializedObject.ApplyModifiedProperties();

                CheckUpdates();

                serializedObject.Update();

                //adjust
                // RectTransform thisRt = myTarget.transform.GetComponent<RectTransform>();
                RectTransform _rt = ((Image)mask_p.objectReferenceValue).rectTransform;
                // _rt.anchorMin = thisRt.anchorMin;
                // _rt.anchorMax = thisRt.anchorMax;
                //_rt.pivot = thisRt.pivot;
                _rt.anchoredPosition = new Vector2((myTarget.barSets.Count - 1) * myTarget.size.x, 0);
                _rt.localScale       = Vector3.one;

                myTarget.MainGauge();
                myTarget.RequiredGauge();
                HideGos();
            }
        }
        if (barSets_p.arraySize > 0)
        {
            GUI.enabled = true;
        }
        else
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("- Notch"))
        {
            if (Application.isPlaying)
            {
                myTarget.RemoveNotch();
            }
            else
            {
                //delete check
                serializedObject.Update();

                int id = barSets_p.arraySize - 1;
                SerializedProperty mask_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("mask");
                if (mask_p.objectReferenceValue != null)
                {
                    DestroyGo(((Image)mask_p.objectReferenceValue).gameObject);
                    serializedObject.ApplyModifiedProperties();
                }

                SerializedProperty img_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("img");
                if (img_p.objectReferenceValue != null)
                {
                    DestroyGo(((Image)img_p.objectReferenceValue).gameObject);
                    serializedObject.ApplyModifiedProperties();
                }

                SerializedProperty requiredImg_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("requiredImg");
                if (requiredImg_p.objectReferenceValue != null)
                {
                    DestroyGo(((Image)requiredImg_p.objectReferenceValue).gameObject);
                    serializedObject.ApplyModifiedProperties();
                }
                SerializedProperty requiredMask_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("requiredMask");
                if (requiredMask_p.objectReferenceValue != null)
                {
                    DestroyGo(((Image)requiredMask_p.objectReferenceValue).gameObject);
                    serializedObject.ApplyModifiedProperties();
                }

                SerializedProperty bleedImg_p = barSets_p.GetArrayElementAtIndex(id).FindPropertyRelative("bleedImg");
                if (bleedImg_p.objectReferenceValue != null)
                {
                    DestroyGo(((Image)bleedImg_p.objectReferenceValue).gameObject);
                    serializedObject.ApplyModifiedProperties();
                }
                ;
                barSets_p.DeleteArrayElementAtIndex(barSets_p.arraySize - 1);
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();

                CheckUpdates();
                myTarget.MainGauge();
                myTarget.RequiredGauge();
                HideGos(showDebug);
            }
        }
        GUI.enabled = true;

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.Space(20);


        base.OnInspectorGUI();



        serializedObject.ApplyModifiedProperties();
        serializedObject.Update();
    }