Ejemplo n.º 1
0
        public void CommonInit(AmplifyShaderFunction function)
        {
            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);

            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            m_functionCheckSum = LastLine(m_function.FunctionInfo);
            List <ParentNode> propertyList = UIUtils.PropertyNodesList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs  = new List <FunctionInput>();
            m_allFunctionOutputs = new List <FunctionOutput>();

            for (int i = 0; i < m_functionGraph.AllNodes.Count; i++)
            {
                //Debug.Log( m_functionGraph.AllNodes[ i ].GetType()+" "+ m_functionGraph.AllNodes[ i ].IsConnected );
                if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionInput))
                {
                    m_allFunctionInputs.Add(m_functionGraph.AllNodes[i] as FunctionInput);
                }
                else if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionOutput))
                {
                    m_allFunctionOutputs.Add(m_functionGraph.AllNodes[i] as FunctionOutput);
                }
            }

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int outputCount = m_allFunctionOutputs.Count;

            for (int i = 0; i < outputCount; i++)
            {
                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;
        }
Ejemplo n.º 2
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_refreshIdsRequired = UIUtils.IsLoading && (UIUtils.CurrentShaderVersion() < 14004);

            m_function = function;

            if (Function.FunctionName.Length > 1)
            {
                bool lastIsUpper = Char.IsUpper(Function.FunctionName, 0);
                System.Text.StringBuilder title = new System.Text.StringBuilder();
                title.Append(Function.FunctionName[0]);
                for (int i = 1; i < Function.FunctionName.Length; i++)
                {
                    bool currIsUpper = Char.IsUpper(Function.FunctionName, i);
                    if (currIsUpper && !lastIsUpper && Char.IsLetter(Function.FunctionName[i - 1]))
                    {
                        title.Append(" ");
                    }
                    lastIsUpper = currIsUpper;
                    title.Append(Function.FunctionName[i]);
                    SetTitleText(title.ToString());
                }
            }
            else
            {
                SetTitleText(Function.FunctionName);
            }
            m_tooltipText    = Function.Description;
            m_hasTooltipLink = false;
            if (m_functionGraph == null)
            {
                //m_functionGraph = new ParentGraph();
                m_functionGraph = CreateInstance <ParentGraph>();
                m_functionGraph.Init();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs   = UIUtils.FunctionInputList();
            m_allFunctionOutputs  = UIUtils.FunctionOutputList();
            m_allFunctionSwitches = UIUtils.FunctionSwitchList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionSwitches.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                if (m_refreshIdsRequired)
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                }
                else
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName, -1, MasterNodePortCategory.Fragment, m_allFunctionInputs[i].UniqueId);
                }
                InputPortSwitchRestriction(m_inputPorts[i]);

                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected)
                {
                    m_inputPorts[i].AutoDrawInternalData = true;
                    m_inputPorts[i].InternalData         = m_allFunctionInputs[i].InputPorts[0].InternalData;
                }
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                if (m_refreshIdsRequired)
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                }
                else
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName, m_allFunctionOutputs[i].UniqueId);
                }
                OutputPortSwitchRestriction(m_outputPorts[i]);
            }

            // make sure to hide the ports properly
            CheckPortVisibility();

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 120;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID   = "aca70c900c50c004e8ef0b47c4fac4d4";
            m_useInternalPortData = false;
            m_selectedLocation    = function.PreviewPosition;
        }
Ejemplo n.º 3
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);
            m_tooltipText = Function.Description;
            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs  = UIUtils.FunctionInputList();
            m_allFunctionOutputs = UIUtils.FunctionOutputList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID = "aca70c900c50c004e8ef0b47c4fac4d4";
        }