Ejemplo n.º 1
0
        public void Initialize()
        {
            if (ConstellationData == null && Application.isPlaying)
            {
                this.enabled = false;
                throw new NoConstellationAttached(this);
            }

            if (isInitialized) // do not initialize twice
            {
                return;
            }

            if (ConstellationComponent.eventSystem == null)
            {
                eventSystem = new ConstellationEventSystem();
            }

            if (NodesFactory.Current == null)
            {
                nodeFactory = new NodesFactory(ConstellationData?.ScriptAssembly?.GetAllScriptData());
            }
            else
            {
                nodeFactory = NodesFactory.Current;
            }

            var nodes = ConstellationData.GetNodes();

            constellation = new Constellation();
            SetNodes(nodes);

            var links = ConstellationData.GetLinks();

            foreach (LinkData link in links)
            {
                var input  = constellation.GetInput(link.Input.Guid);
                var output = constellation.GetOutput(link.Output.Guid);
                if (input != null && output != null)
                {
                    constellation.AddLink(new Link(constellation.GetInput(link.Input.Guid),
                                                   constellation.GetOutput(link.Output.Guid),
                                                   constellation.GetOutput(link.Output.Guid).Type, link.GUID));
                }
            }

            SetUnityObject();
            constellation.Initialize(System.Guid.NewGuid().ToString(), ConstellationData.name);
            if (constellation.GetInjector() is IAwakable)
            {
                constellation.GetInjector().OnAwake();
            }
            isInitialized = true;
        }
Ejemplo n.º 2
0
        public void Awake()
        {
            if (ConstellationBehaviour.eventSystem == null)
            {
                eventSystem = new ConstellationEventSystem();
            }

            if (NodesFactory.Current == null)
            {
                nodeFactory = new NodesFactory();
            }
            else
            {
                nodeFactory = NodesFactory.Current;
            }

            if (ConstellationData == null && Application.isPlaying)
            {
                this.enabled = false;
                Debug.LogError("Constellation Error: No Constellation attached to " + this.gameObject);
                return;
            }
            var nodes = ConstellationData.GetNodes();

            Constellation = new Constellation();
            SetNodes(nodes);

            var links = ConstellationData.GetLinks();

            foreach (LinkData link in links)
            {
                Constellation.AddLink(new Link(Constellation.GetInput(link.Input.Guid),
                                               Constellation.GetOutput(link.Output.Guid),
                                               Constellation.GetOutput(link.Output.Guid).Type), "none");
            }
            SetUnityObject();
            SetConstellationEvents();
            Constellation.Initialize(System.Guid.NewGuid().ToString(), ConstellationData.name);
            Constellation.Awake();
        }