예제 #1
0
 public void ClearAsset(OutputSlot output)
 {
     if (output.persistedAsset != null)
     {
         AssetUtility.DeleteAsset(output.persistedAsset);
     }
 }
예제 #2
0
 public static void ResetAssetTypeIfNull <TAsset>(OutputSlot outputSlot)
 {
     if (outputSlot != null && outputSlot._assetType.type == null)
     {
         outputSlot._assetType = typeof(TAsset);
     }
 }
예제 #3
0
        public Object SetAsset(OutputSlot output, Object asset)
        {
            if (asset != null)
            {
                if (ShouldPersist(output))
                {
                    Object persistedAsset = output.persistedAsset;

                    if ((output.availability & OutputSlot.Availability.AfterGeneration) != 0)
                    {
                        persistedAsset = PersistAsset(persistedAsset, asset, output.name, output.path);
                    }
                    else
                    {
                        persistedAsset = PersistHiddenAsset(persistedAsset, asset, output.name);
                    }

                    return(persistedAsset);
                }
                else
                {
                    return(asset);
                }
            }
            else
            {
                ClearAsset(output);
                return(null);
            }
        }
예제 #4
0
        protected override void Initialize()
        {
            // Fields
            randomness.Initialize(this);

            // Outputs
            OutputSlot.CreateOrResetUnpersisted <IRandom>(ref randomOutputSlot, this, "Randomness", true);
        }
예제 #5
0
        public static OutputSlotKey Create(OutputSlot slot, Generator generator)
        {
            var instance = CreateInstance <OutputSlotKey>();

            instance._slot      = slot;
            instance._generator = generator;
            instance.hideFlags  = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
            return(instance);
        }
예제 #6
0
 public static OutputSlot CreateOrResetUnpersisted <TAsset>(ref OutputSlot output, Generator generator, string name, bool isEnabled = true)
 {
     if (output == null)
     {
         output = new OutputSlot();
     }
     output.Initialize(generator, typeof(TAsset), name, null, isEnabled, Availability.DuringGeneration, false);
     return(output);
 }
예제 #7
0
 public static OutputSlot CreateOrResetGrouped <TAsset>(ref OutputSlot output, Generator generator, string name, string path, bool isEnabled = true, Availability availability = Availability.Always)
 {
     if (output == null)
     {
         output = new OutputSlot();
     }
     output.Initialize(generator, typeof(TAsset), name, path, isEnabled, availability, true);
     return(output);
 }
예제 #8
0
 public virtual void ResetDependency(OutputSlot dependency)
 {
     foreach (var input in activeInputs)
     {
         if (ReferenceEquals(input.source, dependency))
         {
             input.Disconnect();
         }
     }
 }
예제 #9
0
 public InternalSlotConnection(OutputSlot source, OutputSlot target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     this.source = source;
     this.target = target;
 }
예제 #10
0
        public void OnAfterDeserialize()
        {
            randomness.ResetIfBroken(this);

            if (randomOutputSlot != null && randomOutputSlot.generator != null)
            {
                OutputSlot.ResetAssetTypeIfNull <IRandom>(randomOutputSlot);
            }
            else
            {
                OutputSlot.CreateOrResetUnpersisted <IRandom>(ref randomOutputSlot, this, "Randomness", true);
            }
        }
예제 #11
0
        private bool ShouldPersist(OutputSlot output)
        {
            if (output.isEnabled == false)
            {
                return(false);
            }
            if ((output.availability & OutputSlot.Availability.AfterGeneration) != 0)
            {
                return(true);
            }

            foreach (var reference in output.generator.internalConnections)
            {
                if (ReferenceEquals(reference.source, output))
                {
                    if (ShouldPersist(reference.target))
                    {
                        return(true);
                    }
                }
            }

            foreach (var consumer in output.connections)
            {
                foreach (var reference in consumer.generator.internalConnections)
                {
                    if (ReferenceEquals(reference.source, output))
                    {
                        if (ShouldPersist(reference.target))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #12
0
        public static bool OnInspectorGUI(OutputSlot output, bool foldout, AnimBool foldoutAnimation)
        {
            InitializeStyles();

            float foldoutMinWidth, foldoutMaxWidth;

            EditorStyles.foldout.CalcMinMaxWidth(GUIContent.none, out foldoutMinWidth, out foldoutMaxWidth);

            EditorGUILayout.BeginVertical(_outlineStyle);

            EditorGUILayout.BeginHorizontal();
            var foldoutRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, GUILayout.Width(0));

            foldout = EditorGUI.Foldout(foldoutRect, foldout, GUIContent.none, false);
            foldoutAnimation.target = foldout;
            EditorGUILayout.BeginVertical();

            if (foldout)
            {
                EditorGUILayout.BeginHorizontal();
                output.isEnabled = EditorGUILayout.ToggleLeft("Enabled", output.isEnabled, GUILayout.Width(EditorStyles.toggle.CalcSize(new GUIContent("Enabled")).x));
                GUIExtensions.PushEnable(output.isEnabled);
                if (output.mustBeAvailableAfterGeneration)
                {
                    output.availability = (OutputSlot.Availability)EditorGUILayout.IntPopup((int)output.availability, _alwaysAfterAvailabilityContent, _alwaysAfterAvailabilityValues);
                }
                else if (output.canBeAvailableAfterGeneration)
                {
                    output.availability = (OutputSlot.Availability)EditorGUILayout.IntPopup((int)output.availability, _fullAvailabilityContent, _fullAvailabilityValues);
                }
                else
                {
                    output.availability = (OutputSlot.Availability)EditorGUILayout.IntPopup((int)output.availability, _neverAfterAvailabilityContent, _neverAfterAvailabilityValues);
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                output.isEnabled = EditorGUILayout.Toggle(output.isEnabled, GUILayout.Width(EditorStyles.toggle.CalcSize(GUIContent.none).x));
                GUIExtensions.PushEnable(output.isEnabled);
                EditorGUILayout.LabelField(new GUIContent(string.Format("{0} ({1})", output.name, output.assetType.GetPrettyName()), output.assetType.GetPrettyName(true)));
                EditorGUILayout.EndHorizontal();
            }

            if (EditorGUILayout.BeginFadeGroup(foldoutAnimation.faded))
            {
                var priorLabelWidth = EditorGUIUtility.labelWidth;

                var labelWidth = 0f;
                labelWidth = Mathf.Max(labelWidth, EditorStyles.label.CalcSize(new GUIContent("Name")).x);
                labelWidth = Mathf.Max(labelWidth, EditorStyles.label.CalcSize(new GUIContent("Type")).x);
                if (output.canBeGrouped)
                {
                    labelWidth = Mathf.Max(labelWidth, EditorStyles.label.CalcSize(new GUIContent("Group")).x);
                }

                EditorGUIUtility.labelWidth = labelWidth;
                output.name = EditorGUILayout.TextField("Name", output.name);

                if (output.canBeGrouped)
                {
                    EditorGUILayout.BeginHorizontal();
                    output.path = EditorGUILayout.TextField("Path", output.path);
                    var assetPaths       = output.generator.executive.GetAllAssetPaths("<none>");
                    var currentPathIndex = System.Array.IndexOf(assetPaths, output.path);
                    if (currentPathIndex == -1)
                    {
                        currentPathIndex = 0;
                    }
                    currentPathIndex = EditorGUILayout.Popup(currentPathIndex, assetPaths, GUILayout.Width(EditorGUIUtility.singleLineHeight));
                    output.path      = currentPathIndex == 0 ? "" : assetPaths[currentPathIndex];
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Type");
                EditorGUILayout.SelectableLabel(output.assetType.GetPrettyName(), EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                EditorGUILayout.EndHorizontal();
                var typeRect = GUILayoutUtility.GetLastRect();
                GUI.Label(typeRect, new GUIContent("", output.assetType.GetPrettyName(true)));

                EditorGUIUtility.labelWidth = priorLabelWidth;
            }
            EditorGUILayout.EndFadeGroup();

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            GUIExtensions.PopEnable();

            return(foldout);
        }
예제 #13
0
 public InternalSlotConnection Uses(OutputSlot source)
 {
     return(new InternalSlotConnection(source, this));
 }
예제 #14
0
 public InternalSlotConnection UsedBy(OutputSlot target)
 {
     return(new InternalSlotConnection(this, target));
 }