Exemplo n.º 1
0
        /// <summary>
        /// Subscribe to the given event on the given target object
        /// </summary>
        /// <param name="targetEvent"></param>
        /// <param name="target"></param>
        public void Subscribe(FieldInfo targetKlaxEvent, object target)
        {
            // Unsubscribe in case we are subscribed to another event currently
            Unsubscribe();

            if (TargetComponentGuid != Guid.Empty && target is CEntity baseEntity)
            {
                CEntityComponent targetComponent = baseEntity.GetComponentByGuid(TargetComponentGuid);
                if (targetComponent == null)
                {
                    throw new Exception("Event graphs tried to bind to a component event of a component that does not exist on the parent entity");
                }

                target = targetComponent;
            }

            //Validate that the event handler has the correct form
            CKlaxScriptEventBase klaxEvent = (CKlaxScriptEventBase)TargetEvent.klaxEventInfo.GetValue(target);

            if (klaxEvent == null)
            {
                throw new NullReferenceException("The given event has an invalid handler");
            }

            klaxEvent.Subscribe(Execute);
            m_eventSource   = target;
            m_bIsSubscribed = true;
        }
        public CComponentVariableNode(CEntityComponent targetComponent)
        {
            IsImplicit = true;

            Name = "Get " + targetComponent.Name;
            ComponentTargetGuid = targetComponent.ComponentGuid;

            COutputPin output = new COutputPin(targetComponent.Name, targetComponent.GetType());

            OutputPins.Add(output);
        }
Exemplo n.º 3
0
        private void InspectComponent(SEntityComponentId componentId)
        {
            bool bUpdateInspectorObjectList = ShouldUpdateInspectorList(componentId);

            CEngine engine = CEngine.Instance;
            CWorldOutlinerViewModel worldOutliner = CWorkspace.Instance.GetTool <CWorldOutlinerViewModel>();

            engine.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CUpdateScheduler scheduler = engine.CurrentWorld.UpdateScheduler;
                if (m_updateScope != null && m_updateScope.IsConnected())
                {
                    scheduler.Disconnect(m_updateScope);
                }

                CEntityComponent component = componentId.GetComponent();
                if (component != null)
                {
                    m_selectedObject = new CEditableObject(componentId);
                    m_updateScope    = scheduler.Connect(UpdateCallback, EUpdatePriority.ResourceLoading);

                    if (bUpdateInspectorObjectList)
                    {
                        UpdateEntityInformation_EngineThread(new SEntityId(component.Owner.Id));
                    }

                    worldOutliner.PickingComponentId.GetComponent <CScenePickingComponent>().Pick(component as CSceneComponent);

                    Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                    {
                        m_desiredTarget = new CEditableObject(componentId);
                        UnmarkEverything();
                        MarkComponentInInspector(componentId, true);
                    }));
                }
                else
                {
                    Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                    {
                        m_desiredTarget = null;
                        UnmarkEverything();
                    }));
                }
            });
        }
        public override CExecutionPin Execute(CNodeExecutionContext context, List <object> inParameters, List <object> outReturn)
        {
            if (context.graph.ScriptableObject.Outer is CEntity entity)
            {
                CEntityComponent outComponent = entity.GetComponentByGuid(ComponentTargetGuid);
#if DEBUG
                if (outComponent == null || outComponent.GetType() != OutputPins[0].Type)
                {
                    LogUtility.Log("Receive component node failed. The given component did not exist or was of a different type than expected");
                    outReturn.Add(null);
                    return(null);
                }
#endif
                outReturn.Add(outComponent);
            }
            else
            {
                outReturn.Add(null);
            }

            return(null);
        }
Exemplo n.º 5
0
        public static void DestroyComponent(SEntityComponentId id)
        {
            if (id.OverrideComponent == null)
            {
                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    CEntityComponent component = id.GetComponent <CEntityComponent>();
                    if (component != null)
                    {
                        component.Destroy();
                    }
                });
            }
            else
            {
                CEntityComponent component = id.GetComponent <CEntityComponent>();
                if (component != null)
                {
                    component.Destroy();
                }
            }

            UndoRedoUtility.Purge(null);
        }