예제 #1
0
        protected override void OnEnable()
        {
            base.OnEnable();

            m_Type          = serializedObject.FindProperty("m_Type");
            m_FillMethod    = serializedObject.FindProperty("m_FillMethod");
            m_FillOrigin    = serializedObject.FindProperty("m_FillOrigin");
            m_FillClockwise = serializedObject.FindProperty("m_FillClockwise");
            m_FillAmount    = serializedObject.FindProperty("m_FillAmount");
            m_Sprite        = serializedObject.FindProperty("m_Sprite");

            var typeEnum = (Image.Type)m_Type.enumValueIndex;

            showFilled = new AnimBool(!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Filled);
            showFilled.valueChanged.AddListener(Repaint);

            attrList = ModifierUtility.GetAttributeList();

            m_borderWidth = serializedObject.FindProperty("borderWidth");
            m_falloffDist = serializedObject.FindProperty("falloffDistance");

            if ((target as ProceduralImage).GetComponent <ProceduralImageModifier>() != null)
            {
                selectedId = attrList.IndexOf(((ModifierID[])(target as ProceduralImage).GetComponent <ProceduralImageModifier>().GetType().GetCustomAttributes(typeof(ModifierID), false))[0]);
            }
            selectedId = Mathf.Max(selectedId, 0);
            EditorApplication.update -= UpdateProceduralImage;
            EditorApplication.update += UpdateProceduralImage;
        }
예제 #2
0
        protected void ModifierGUI()
        {
            GUIContent[] con = new GUIContent[attrList.Count];
            for (int i = 0; i < con.Length; i++)
            {
                con[i] = new GUIContent(attrList[i].Name);
            }


            bool hasMultipleValues = false;

            if (targets.Length > 1)
            {
                Type t = (targets[0] as ProceduralImage).GetComponent <ProceduralImageModifier>().GetType();
                foreach (var item in targets)
                {
                    if ((item as ProceduralImage).GetComponent <ProceduralImageModifier>().GetType() != t)
                    {
                        hasMultipleValues = true;
                        break;
                    }
                }
            }

            if (!hasMultipleValues)
            {
                int index = EditorGUILayout.Popup(new GUIContent("Modifier Type"), selectedId, con);
                if (selectedId != index)
                {
                    selectedId = index;
                    foreach (var item in targets)
                    {
                        (item as ProceduralImage).ModifierType = ModifierUtility.GetTypeWithId(attrList[selectedId].Name);

                        MoveComponentBehind((item as ProceduralImage), (item as ProceduralImage).GetComponent <ProceduralImageModifier>());
                    }
                    //Exit GUI prevents Unity from trying to draw destroyed components editor;
                    EditorGUIUtility.ExitGUI();
                }
            }
            else
            {
                int index = EditorGUILayout.Popup(new GUIContent("Modifier Type"), -1, con);
                if (index != -1)
                {
                    selectedId = index;
                    foreach (var item in targets)
                    {
                        (item as ProceduralImage).ModifierType = ModifierUtility.GetTypeWithId(attrList[selectedId].Name);

                        MoveComponentBehind((item as ProceduralImage), (item as ProceduralImage).GetComponent <ProceduralImageModifier>());
                    }
                    //Exit GUI prevents Unity from trying to draw destroyed components editor;
                    EditorGUIUtility.ExitGUI();
                }
            }
        }