Ejemplo n.º 1
0
        public PureDataContainer(string name, PureData pureData)
        {
            this.name     = name;
            this.pureData = pureData;

            switchSettings = new PureDataSwitchSettings(pureData);
        }
Ejemplo n.º 2
0
        void ShowSwitchContainerEnums(SerializedProperty property, PureDataSwitchSettings switchSettings)
        {
            Rect rect = EditorGUILayout.BeginHorizontal();

            // State holder
            EditorGUI.BeginChangeCheck();

            switchSettings.StateHolder = EditorGUILayout.ObjectField("State Holder".ToGUIContent(), switchSettings.StateHolderObject, typeof(UnityEngine.Object), true, GUILayout.MaxWidth(switchSettings.StateHolderObject == null ? Screen.width : Screen.width / 1.6F));

            // Component list
            if (switchSettings.StateHolderObject != null)
            {
                List <string> componentNames = new List <string> {
                    "GameObject"
                };
                Component[] components = switchSettings.StateHolderObject.GetComponents <Component>();

                foreach (Component component in components)
                {
                    componentNames.Add(component.GetType().Name);
                }

                float width = Mathf.Min(92 + EditorGUI.indentLevel * 16, EditorGUIUtility.currentViewWidth / 5 + EditorGUI.indentLevel * 16);
                int   index = EditorGUI.Popup(new Rect(rect.x + rect.width - width, rect.y, width, rect.height), Array.IndexOf(components, switchSettings.StateHolderComponent) + 1, componentNames.ToArray());

                switchSettings.StateHolderComponent = index > 0 ? components[index - 1] : null;
            }

            EditorGUILayout.EndHorizontal();

            // State field
            if (switchSettings.StateHolder != null)
            {
                string[] enumNames = switchSettings.StateHolder.GetFieldsPropertiesNames(ObjectExtensions.AllPublicFlags, typeof(Enum));

                if (enumNames.Length > 0)
                {
                    int index = Mathf.Max(Array.IndexOf(enumNames, switchSettings.statePath), 0);
                    index = EditorGUILayout.Popup("State Field", index, enumNames);
                    switchSettings.statePath = enumNames[Mathf.Clamp(index, 0, Mathf.Max(enumNames.Length - 1, 0))];
                }
                else
                {
                    EditorGUILayout.Popup("State Field", 0, new string[0]);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.Update();
            }
        }
Ejemplo n.º 3
0
        public PureDataSubContainer(PureDataContainer container, int parentId, PureData pureData)
        {
            this.name           = container.Name;
            this.id             = container.GetUniqueID();
            this.parentId       = parentId;
            this.pureData       = pureData;
            this.switchSettings = new PureDataSwitchSettings(pureData);

            if (parentId == 0)
            {
                container.childrenIds.Add(id);
            }
            else
            {
                container.GetSubContainerWithID(parentId).childrenIds.Add(id);
            }
        }
Ejemplo n.º 4
0
        void ShowGeneralContainerSettings()
        {
            currentSubContainer.type = (PureDataSubContainer.Types)EditorGUILayout.EnumPopup(currentSubContainer.type);

            if (GetParentContainerType(currentSubContainer, currentContainer) == PureDataSubContainer.Types.RandomContainer)
            {
                EditorGUILayout.PropertyField(currentSubContainerProperty.FindPropertyRelative("weight"));
            }
            else if (GetParentContainerType(currentSubContainer, currentContainer) == PureDataSubContainer.Types.SwitchContainer)
            {
                PureDataSwitchSettings parentSwitchSettings = currentSubContainer.parentId == 0 ? currentContainer.switchSettings : currentContainer.GetSubContainerWithID(currentSubContainer.parentId).switchSettings;
                PureDataSwitchSettings switchSettings       = currentSubContainer.switchSettings;

                if (parentSwitchSettings.StateHolder != null && !string.IsNullOrEmpty(parentSwitchSettings.statePath))
                {
                    FieldInfo    enumField    = parentSwitchSettings.StateHolder.GetType().GetField(parentSwitchSettings.statePath, ObjectExtensions.AllPublicFlags);
                    PropertyInfo enumProperty = parentSwitchSettings.StateHolder.GetType().GetProperty(parentSwitchSettings.statePath, ObjectExtensions.AllPublicFlags);
                    Type         enumType     = enumField == null ? enumProperty == null ? null : enumProperty.PropertyType : enumField.FieldType;

                    if (enumType != null)
                    {
                        string[] enumNames     = Enum.GetNames(enumType);
                        Enum     defaultState  = (Enum)Enum.Parse(enumType, enumNames[0]);
                        Enum     selectedState = Enum.GetNames(enumType).Contains(switchSettings.stateName) ? (Enum)Enum.Parse(enumType, switchSettings.stateName) : null;
                        Enum     selectedEnum  = selectedState == null?EditorGUILayout.EnumPopup("State", defaultState) : EditorGUILayout.EnumPopup("State", selectedState);

                        switchSettings.stateName  = selectedEnum.ToString();
                        switchSettings.stateIndex = selectedEnum.GetHashCode();

                        return;
                    }
                }

                EditorGUILayout.Popup("State", 0, new string[0]);
            }
        }
		public PureDataSubContainer(PureDataContainer container, int parentId, PureDataSubContainer subContainer, PureData pureData) {
			this.Copy(subContainer, "id", "parentId", "childrenIds");
			
			this.name = container.Name;
			this.id = container.GetUniqueID();
			this.parentId = parentId;
			this.pureData = pureData;
			
			switchSettings = new PureDataSwitchSettings(pureData);
			
			if (parentId == 0) {
				container.childrenIds.Add(id);
			}
			else {
				container.GetSubContainerWithID(parentId).childrenIds.Add(id);
			}
		}
Ejemplo n.º 6
0
		void ShowSwitchContainerEnums(SerializedProperty property, PureDataSwitchSettings switchSettings) {
			Rect rect = EditorGUILayout.BeginHorizontal();
			
			// State holder
			EditorGUI.BeginChangeCheck();
			
			switchSettings.StateHolder = EditorGUILayout.ObjectField("State Holder".ToGUIContent(), switchSettings.StateHolderObject, typeof(UnityEngine.Object), true, GUILayout.MaxWidth(switchSettings.StateHolderObject == null ? Screen.width : Screen.width / 1.6F));
			
			// Component list
			if (switchSettings.StateHolderObject != null) {
				List<string> componentNames = new List<string>{ "GameObject" };
				Component[] components = switchSettings.StateHolderObject.GetComponents<Component>();
				
				foreach (Component component in components) {
					componentNames.Add(component.GetType().Name);
				}
		
				float width = Mathf.Min(92 + EditorGUI.indentLevel * 16, EditorGUIUtility.currentViewWidth / 5 + EditorGUI.indentLevel * 16);
				int index = EditorGUI.Popup(new Rect(rect.x + rect.width - width, rect.y, width, rect.height), Array.IndexOf(components, switchSettings.StateHolderComponent) + 1, componentNames.ToArray());
				
				switchSettings.StateHolderComponent = index > 0 ? components[index - 1] : null;
			}
			
			EditorGUILayout.EndHorizontal();
		
			// State field
			if (switchSettings.StateHolder != null) {
				string[] enumNames = switchSettings.StateHolder.GetFieldsPropertiesNames(ObjectExtensions.AllPublicFlags, typeof(Enum));
		
				if (enumNames.Length > 0) {
					int index = Mathf.Max(Array.IndexOf(enumNames, switchSettings.statePath), 0);
					index = EditorGUILayout.Popup("State Field", index, enumNames);
					switchSettings.statePath = enumNames[Mathf.Clamp(index, 0, Mathf.Max(enumNames.Length - 1, 0))];
				}
				else {
					EditorGUILayout.Popup("State Field", 0, new string[0]);
				}
			}
			
			if (EditorGUI.EndChangeCheck()) {
				property.serializedObject.Update();
			}
		}
Ejemplo n.º 7
0
		public PureDataContainer(string name, PureData pureData) {
			this.name = name;
			this.pureData = pureData;
			
			switchSettings = new PureDataSwitchSettings(pureData);
		}