コード例 #1
0
ファイル: Node.cs プロジェクト: Arcanafex/Code-Samples
        public void GetComponentsFrom(GameObject gameObject)
        {
            foreach (var component in gameObject.GetComponents <Widget>())
            {
                if (component is MaterialWidget)
                {
                    ((MaterialWidget)component).UpdateWidgetState();
                }
                else if (component is LightWidget)
                {
                    ((LightWidget)component).UpdateWidget();
                }
                else if (component is ParticleWidget)
                {
                    ((ParticleWidget)component).UpdateWidget();
                }

                if (string.IsNullOrEmpty(component.InstanceID))
                {
                    component.GenerateInstanceID();
                }

                var widget = new NodeWidget(component);

                if (widget.NeedsReferenceSerialization())
                {
                    NodeReferenceMap.AddNodeWidget(widget);
                }

                widget.Serialize();

                NodeReferenceMap.AddReference(component, widget);
                widgetMap.Add(widget);
            }
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: Arcanafex/Code-Samples
        public void SetWidgetsFor(GameObject gameObject, bool overwriteWidgetSettings = true)
        {
            var usedWidgets = new List <Component>();

            foreach (var widget in widgetMap)
            {
                var  widgetType     = System.Type.GetType(widget.Type);
                bool existingWidget = false;

                if (widgetType == null)
                {
                    Debug.LogWarning(this.name + " [Widget Type Unknown] " + widget.Type);
                    continue;
                }

                var reconstitutedWidget = gameObject.GetComponents(widgetType).FirstOrDefault(w => !usedWidgets.Contains(w));

                if (reconstitutedWidget)
                {
                    existingWidget = true;
                }
                else
                {
                    reconstitutedWidget = gameObject.AddComponent(widgetType);
                }

                usedWidgets.Add(reconstitutedWidget);
                NodeReferenceMap.AddReference(reconstitutedWidget, widget);

                if (!overwriteWidgetSettings && existingWidget)
                {
                    continue;
                }

                if (widget.NeedsReferenceSerialization())
                {
                    NodeReferenceMap.AddNodeWidget(widget);
                }

                if (reconstitutedWidget)
                {
                    JsonUtility.FromJsonOverwrite(widget.Value, reconstitutedWidget);
                }

                if (reconstitutedWidget is Widget && string.IsNullOrEmpty(((Widget)reconstitutedWidget).InstanceID))
                {
                    ((Widget)reconstitutedWidget).GenerateInstanceID();
                }
            }
        }