Ejemplo n.º 1
0
        protected void OnEnable()
        {
//			rec = false;
            RefleshAllToggles();

            roSyncToggles = new ReorderableList(serializedObject, serializedObject.FindProperty("m_SyncedToggles"), false, false, true, true);
            roSyncToggles.drawElementCallback = (rect, index, isActive, isFocus) =>
            {
                var sp = roSyncToggles.serializedProperty.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField(rect, sp, GetLabelWithWarning("Notifiy Target", sp.objectReferenceValue as CompositeToggle));
            };
            roSyncToggles.elementHeight = 16;
            roSyncToggles.headerHeight  = 0;

            current = target as CompositeToggle;
            current.Reflesh();

            spComments       = serializedObject.FindProperty("m_Comments");
            spActions        = serializedObject.FindProperty("m_Actions");
            spGroupToggles   = serializedObject.FindProperty("m_GroupedToggles");
            spActivations    = serializedObject.FindProperty("m_ActivateObjects");
            spOnValueChanged = serializedObject.FindProperty("m_OnValueChanged");

            spValueType          = serializedObject.FindProperty("m_ValueType");
            spIgnoreParentToggle = serializedObject.FindProperty("m_IgnoreParent");
            spResetValueOnAwake  = serializedObject.FindProperty("m_ResetValueOnAwake");
            spSyncedToggles      = serializedObject.FindProperty("m_SyncedToggles");

            s_AvailableReflectedTypes = new HashSet <Type>(current.GetComponents <Component>().Where(x => x != null).Select(x => x.GetType()));
            s_AvailableReflectedTypes.Add(typeof(GameObject));

            syncedByOtherToggles.Clear();
            foreach (var toggle in Resources.FindObjectsOfTypeAll <CompositeToggle>())
            {
                if (toggle == current)
                {
                    continue;
                }

                var sp = new SerializedObject(toggle).FindProperty("m_SyncedToggles");
                if (Enumerable.Range(0, sp.arraySize).Any(i => sp.GetArrayElementAtIndex(i).objectReferenceValue == current))
                {
                    syncedByOtherToggles.Add(toggle);
                }
            }

            UpdateMultipleRelations();
        }
Ejemplo n.º 2
0
        IEnumerator CreateInstanceOnNextFrame(GameObject obj)
        {
            yield return(new WaitForEndOfFrame());

            var go = GameObject.Instantiate(obj);

            go.transform.SetParent(transform.parent);
            go.transform.localPosition = Vector3.zero;
            go.transform.localScale    = Vector3.one;
            go.transform.localRotation = Quaternion.identity;

            Button          b = go.GetComponentInChildren <Button>();
            CompositeToggle c = go.GetComponentInChildren <CompositeToggle>();

            b.onClick.AddListener(c.Toggle);
        }
Ejemplo n.º 3
0
        GUIContent GetLabelWithWarning(string label, CompositeToggle otherToggle)
        {
            if (!otherToggle)
            {
                return(new GUIContent(label));
            }

            s_StringBuilder.Length = 0;

            // Self-reference.
            if (current == otherToggle)
            {
                s_StringBuilder.AppendFormat("- You can not specify the toggle in itself.\n");
            }

            // Conflict reference.
            if (multipleRelations.Contains(otherToggle))
            {
                s_StringBuilder.AppendFormat("- The toggle can not have multiple relations.\n");
            }

            // Value type or toggole count is mismatched.
            if (!current.groupedToggles.Contains(otherToggle))
            {
                bool isIndexedBoth = (current.valueType <= ValueType.Index && otherToggle.valueType <= ValueType.Index);
                if (!isIndexedBoth && current.valueType != otherToggle.valueType)
                {
                    s_StringBuilder.AppendFormat("- Value type is mismatched: {0}\n", otherToggle.valueType);
                }

                if (current.count != otherToggle.count)
                {
                    s_StringBuilder.AppendFormat("- Toggle count is mismatched: {0}\n", otherToggle.count);
                }
            }

            if (0 < s_StringBuilder.Length)
            {
                s_StringBuilder.Length--;
                return(new GUIContent(label, EditorGUIUtility.FindTexture("console.warnicon.sml"), s_StringBuilder.ToString()));
            }
            else
            {
                return(new GUIContent(label));
            }
        }