Esempio n. 1
0
        public override void SetSetting(NodeSetting setting, object value)
        {
            switch (setting.type)
            {
            case NodeSetting.SettingType.Text:
                if (value == setting.currentValue)
                {
                    return;
                }
                setting.currentValue = value;
                ButtonTextChanged(this, (string)value);
                break;

            case NodeSetting.SettingType.SendPlayerId:
            {
                if (value == setting.currentValue)
                {
                    return;
                }
                base.SetSetting(setting, value);
                Type acceptedType = (bool)value ? typeof(int) : typeof(bool);
                foreach (OutputPort output in outputPorts)
                {
                    output.expectedType = acceptedType;
                }
                break;
            }

            default:
                base.SetSetting(setting, value);
                break;
            }
        }
Esempio n. 2
0
 override protected NodeSetting[] CreateSettings()
 {
     return(new NodeSetting[]
     {
         NodeSetting.CreateSetting(NodeSetting.SettingType.ContinuousOutput),
     });
 }
Esempio n. 3
0
 override protected NodeSetting[] CreateSettings()
 {
     return(new NodeSetting[]
     {
         NodeSetting.CreateSetting(NodeSetting.SettingType.LoopingTimer),
     });
 }
Esempio n. 4
0
        public override void SetSetting(NodeSetting setting, object value)
        {
            if (setting.type != NodeSetting.SettingType.NodeDataType)
            {
                base.SetSetting(setting, value);
            }
            else
            {
                if (value == setting.currentValue)
                {
                    return;
                }
                setting.currentValue = value;

                Type newType = ((NodeSetting.DataType)value).SytemType;
                for (int i = 1; i < settings.Length; i++)
                {
                    NodeSetting s = settings[i];
                    s.valueType = newType;
                    try
                    {
                        s.currentValue = Convert.ChangeType(s.currentValue, newType);
                    }
                    catch (FormatException)
                    {
                        s.currentValue = Activator.CreateInstance(newType);
                    }
                    DebugUtils.Assert(s.currentValue != null);
                    DebugUtils.Assert(s.currentValue.GetType() == newType);
                }

                EmitEvaluationRequired();
            }
        }
Esempio n. 5
0
 public virtual void SetSetting(NodeSetting setting, object value)
 {
     if (value == setting.currentValue)
     {
         return;
     }
     setting.currentValue = value;
     EmitEvaluationRequired();
 }
Esempio n. 6
0
 override protected NodeSetting[] CreateSettings()
 {
     return(new NodeSetting[]
     {
         NodeSetting.CreateSetting(NodeSetting.SettingType.NodeDataType),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Output0),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Output1),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Output2),
     });
 }
Esempio n. 7
0
        protected override NodeSetting[] CreateSettings()
        {
            NodeSetting textSetting = NodeSetting.CreateSetting(NodeSetting.SettingType.Text);

            textSetting.currentValue = "Press Me!";
            return(new NodeSetting[]
            {
                NodeSetting.CreateSetting(NodeSetting.SettingType.SendPlayerId),
                textSetting,
            });
        }
Esempio n. 8
0
 override protected NodeSetting[] CreateSettings()
 {
     return(new NodeSetting[]
     {
         NodeSetting.CreateSetting(NodeSetting.SettingType.StateMinTimeInState),
         NodeSetting.CreateSetting(NodeSetting.SettingType.StateValue0),
         NodeSetting.CreateSetting(NodeSetting.SettingType.StateValue1),
         NodeSetting.CreateSetting(NodeSetting.SettingType.StateValue2),
         NodeSetting.CreateSetting(NodeSetting.SettingType.StateName),
     });
 }
Esempio n. 9
0
		override protected NodeSetting[] CreateSettings()
		{
			return new NodeSetting[]
			{
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition0),
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition1),
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition2),
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition3),
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition4),
				NodeSetting.CreateSetting(NodeSetting.SettingType.SelectorCondition5),
			};
		}
Esempio n. 10
0
 protected override NodeSetting[] CreateSettings()
 {
     return(new NodeSetting[]
     {
         NodeSetting.CreateSetting(NodeSetting.SettingType.Message0),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Message1),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Message2),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Message3),
         NodeSetting.CreateSetting(NodeSetting.SettingType.Message4),
         NodeSetting.CreateSetting(NodeSetting.SettingType.LimitMessage),
     });
 }
Esempio n. 11
0
 public override void SetSetting(NodeSetting setting, object value)
 {
     if (setting.type != NodeSetting.SettingType.StateName)
     {
         base.SetSetting(setting, value);
     }
     else
     {
         if (value == setting.currentValue)
         {
             return;
         }
         setting.currentValue = value;
         StateNameChanged(this, (string)value);
     }
 }
Esempio n. 12
0
        public void Fill()
        {
            List <CircuitNode> nodes = RRCSManager.Instance.circuitManager.Nodes;

            graph = new StorageNode[nodes.Count];
            for (int i = 0; i < graph.Length; i++)
            {
                CircuitNode node = nodes[i];
                DebugUtils.Assert(node.RingEvaluationPriority == i);

                StorageNode storageNode = new StorageNode();
                NodeUi      ui          = UiManager.GetUi(node);
                storageNode.uiType     = ui.GetType().FullName;
                storageNode.typeParams = ui.GetParams();
                storageNode.position   = ui.transform.position;
                storageNode.settings   = new NodeSettingContainer[node.settings.Length];
                for (int j = 0; j < storageNode.settings.Length; j++)
                {
                    NodeSetting setting = node.settings[j];
                    storageNode.settings[j] = new NodeSettingContainer
                    {
                        type  = setting.type,
                        value = setting.currentValue.ToString()
                    };
                }

                graph[i] = storageNode;
            }

            for (int nodeIndex = 0; nodeIndex < graph.Length; nodeIndex++)
            {
                CircuitNode node        = nodes[nodeIndex];
                StorageNode storageNode = graph[nodeIndex];
                storageNode.connections = new NodeConnection[node.inputPorts.Length];
                for (int portIndex = 0; portIndex < node.inputPorts.Length; portIndex++)
                {
                    InputPort port = node.inputPorts[portIndex];
                    if (port.IsConnected)
                    {
                        NodeConnection connection    = new NodeConnection();
                        OutputPort     connectedPort = ((DataConnection)port.connections[0]).SourceDataPort;
                        connection.nodeIndex = connectedPort.RingEvaluationPriority;
                        connection.portIndex = Array.IndexOf(connectedPort.Node.outputPorts, connectedPort);
                        storageNode.connections[portIndex] = connection;
                    }
                }
            }

            for (int nodeIndex = 0; nodeIndex < graph.Length; nodeIndex++)
            {
                CircuitNode node        = nodes[nodeIndex];
                StorageNode storageNode = graph[nodeIndex];

                if (node.statePort != null)
                {
                    List <StateMachineTransition> outgoingTransitions = node.statePort.GetOutgoingTransitions().ToList();
                    storageNode.transitions = new NodeTransition[outgoingTransitions.Count];

                    for (int transitionIndex = 0; transitionIndex < storageNode.transitions.Length; transitionIndex++)
                    {
                        StateMachineTransition outgoingTransition = outgoingTransitions[transitionIndex];
                        NodeTransition         transition         = new NodeTransition
                        {
                            sourceNodeIndex = outgoingTransition.SourceStatePort.RingEvaluationPriority,
                            targetNodeIndex = outgoingTransition.TargetStatePort.RingEvaluationPriority
                        };

                        if (outgoingTransition.TransitionEnabledPort != null && outgoingTransition.TransitionEnabledPort.IsConnected)
                        {
                            OutputPort     connectedPort = ((DataConnection)outgoingTransition.TransitionEnabledPort.connections[0]).SourceDataPort;
                            NodeConnection connection    = new NodeConnection
                            {
                                nodeIndex = connectedPort.RingEvaluationPriority,
                                portIndex = Array.IndexOf(connectedPort.Node.outputPorts, connectedPort)
                            };
                            transition.transitionEnabledConnection = connection;
                        }
                        storageNode.transitions[transitionIndex] = transition;
                    }
                }
                else
                {
                    storageNode.transitions = new NodeTransition[0];
                }
            }
        }
Esempio n. 13
0
        public IEnumerator Restore(RRCSManager manager)
        {
            Dictionary <string, GameObject> typeMap = new Dictionary <string, GameObject>();

            typeMap.Add(typeof(RRButtonUi).FullName,
                        manager.NodeUiPrefabRoot.GetComponentInChildren <RRButtonUi>(true).gameObject);
            typeMap.Add(typeof(StageLightUi).FullName,
                        manager.NodeUiPrefabRoot.GetComponentInChildren <StageLightUi>(true).gameObject);
            typeMap.Add(typeof(SignUi).FullName,
                        manager.NodeUiPrefabRoot.GetComponentInChildren <SignUi>(true).gameObject);
            var chipPrefabs = manager.NodeUiPrefabRoot.GetComponentsInChildren <ChipUi>(true);

            foreach (var prefab in chipPrefabs)
            {
                typeMap.Add(Enum.GetName(typeof(ChipUi.ChipType), prefab.type), prefab.gameObject);
            }
            var gizmoPrefabs = manager.NodeUiPrefabRoot.GetComponentsInChildren <GizmoUi>(true);

            foreach (var prefab in gizmoPrefabs)
            {
                typeMap.Add(Enum.GetName(typeof(GizmoUi.GizmoType), prefab.type), prefab.gameObject);
            }

            Dictionary <NodeSetting.SettingType, int> settingsTypeIndex = new Dictionary <NodeSetting.SettingType, int>();

            foreach (StorageNode storageNode in graph)
            {
                settingsTypeIndex.Clear();
                var typeKey = storageNode.uiType;
                if (typeKey == typeof(ChipUi).FullName)
                {
                    typeKey = storageNode.typeParams;
                }
                if (typeKey == typeof(GizmoUi).FullName)
                {
                    typeKey = storageNode.typeParams;
                }

                if (!typeMap.ContainsKey(typeKey))
                {
                    throw new InvalidOperationException("Invalid node type " + typeKey + ".");
                }
                GameObject go = GameObject.Instantiate(typeMap[typeKey], manager.WorldCanvas.transform);
                go.transform.SetAsFirstSibling();
                NodeUi ui = go.GetComponent <NodeUi>();
                ui.ParseParams(storageNode.typeParams);
                go.transform.position = storageNode.position;
                CircuitNode node = ui.Node;

                foreach (NodeSettingContainer settingContainer in storageNode.settings)
                {
                    int offset;
                    settingsTypeIndex.TryGetValue(settingContainer.type, out offset);
                    int index = Array.FindIndex(node.settings, offset, s => s.type == settingContainer.type);
                    if (index < 0)
                    {
                        Debug.Log("Stored setting " + settingContainer.type + " for type " + typeKey + " not found with offset " + offset + ".");
                        continue;
                    }
                    NodeSetting setting = node.settings[index];
                    DebugUtils.Assert(settingContainer.type == setting.type);
                    setting.ParseValue(settingContainer.value);
                    settingsTypeIndex[settingContainer.type] = index + 1;
                }
            }
            DebugUtils.Assert(manager.circuitManager.Nodes.Count == graph.Length);

            yield return(0);

            List <CircuitNode> nodes = manager.circuitManager.Nodes;

            for (int nodeIndex = 0; nodeIndex < graph.Length; nodeIndex++)
            {
                CircuitNode node        = nodes[nodeIndex];
                StorageNode storageNode = graph[nodeIndex];
                for (int portIndex = 0; portIndex < storageNode.connections.Length; portIndex++)
                {
                    NodeConnection connection = storageNode.connections[portIndex];
                    if (connection.nodeIndex >= 0 && connection.portIndex >= 0)
                    {
                        InputPort  port          = node.inputPorts[portIndex];
                        OutputPort connectedPort = nodes[connection.nodeIndex].outputPorts[connection.portIndex];
                        port.Connect(connectedPort);
                    }
                }

                if (storageNode.transitions != null)
                {
                    foreach (var transition in storageNode.transitions)
                    {
                        var sourceStatePort = nodes[transition.sourceNodeIndex].statePort;
                        sourceStatePort.Connect(nodes[transition.targetNodeIndex].statePort);

                        if (transition.transitionEnabledConnection != null &&
                            transition.transitionEnabledConnection.nodeIndex >= 0 &&
                            transition.transitionEnabledConnection.portIndex >= 0)
                        {
                            StateMachineTransition newTransition =
                                (StateMachineTransition)sourceStatePort.connections[
                                    sourceStatePort.connections.Count - 1];

                            var connectedNode = nodes[transition.transitionEnabledConnection.nodeIndex];
                            var connectedPort =
                                connectedNode.outputPorts[transition.transitionEnabledConnection.portIndex];
                            newTransition.TransitionEnabledPort.Connect(connectedPort);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
 private MonoBehaviour CreateSettingEditor(NodeSetting setting)
 {
     if (setting.valueType == typeof(bool))
     {
         BoolEditor editor = Instantiate <BoolEditor>(boolEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += BoolEditor_ValueChanged;
         return(editor);
     }
     else if (setting.valueType == typeof(int))
     {
         IntEditor editor = Instantiate <IntEditor>(intEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += NumberEditor_ValueChanged <int>;
         return(editor);
     }
     else if (setting.valueType == typeof(long))
     {
         LongEditor editor = Instantiate <LongEditor>(longEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += NumberEditor_ValueChanged <long>;
         return(editor);
     }
     else if (setting.valueType == typeof(float))
     {
         FloatEditor editor = Instantiate <FloatEditor>(floatEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += NumberEditor_ValueChanged <float>;
         return(editor);
     }
     else if (setting.valueType == typeof(double))
     {
         DoubleEditor editor = Instantiate <DoubleEditor>(doubleEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += NumberEditor_ValueChanged <double>;
         return(editor);
     }
     else if (setting.valueType == typeof(string))
     {
         StringEditor editor = Instantiate <StringEditor>(stringEditorPrefab, transform);
         editor.Setting       = setting;
         editor.ValueChanged += StringEditor_ValueChanged;
         return(editor);
     }
     else if (setting.valueType == typeof(NodeSetting.SelectorCondition))
     {
         SelectorConditionEditor editor = Instantiate <SelectorConditionEditor>(selectorConditionEditorPrefab, transform);
         editor.Setting           = setting;
         editor.ConditionChanged += Editor_ConditionChanged;
         return(editor);
     }
     else if (setting.valueType == typeof(NodeSetting.DataType))
     {
         DataTypeEditor editor = Instantiate <DataTypeEditor>(dataTypeEditorPrefab, transform);
         editor.Setting          = setting;
         editor.DataTypeChanged += Editor_DataTypeChanged;
         return(editor);
     }
     else
     {
         DebugUtils.Assert(false);
         return(null);
     }
 }