Exemplo n.º 1
0
        public override async Task <GActor> CreateActor(PlantableItemCreateActorParam param)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var rc = EngineNS.CEngine.Instance.RenderContext;

            var actorInit = new GActor.GActorInitializer();

            actorInit.InPVS = false;
            var actor = new GActor();

            actor.SetInitializer(actorInit);
            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement    = placement;
            placement.Location = param.Location;

            var init = new AgentGeomBoxComponentInitializer();

            init.SpecialName = "AgentStart";
            await SetInitializer(rc, actor, actor, init);

            actor.AddComponent(this);
            return(actor);
        }
Exemplo n.º 2
0
        public async Task <GActor> CreateActor()
        {
            var actor = await GActor.NewMeshActorAsync(ResourceName);

            actor.SpecialName = ResourceName.PureName();
            return(actor);
        }
Exemplo n.º 3
0
        async System.Threading.Tasks.Task CreatePreviewMeshesActor(CGfxMeshPrimitives meshPri, bool initProgressMesh)
        {
            mPreviewActor = await NewMeshActor(meshPri);

            mPreviewActor.Placement.Location = new EngineNS.Vector3(0.0f, 0.0f, 0.0f);
            //mPreviewActor.Placement.Scale *= 0.01f;
            mPreviewSceneControl.AddUniqueActor(mPreviewActor, true);

            mPreviewActor.GetComponentMesh(null).SetPassUserFlags(1);

            //mProgressMesh = new EngineNS.Bricks.MeshProcessor.ProgressMeshProcessor();
            if (initProgressMesh)
            {
                mProgressMesh.InitMesh(EngineNS.CEngine.Instance.RenderContext, meshPri);
                mProgressMesh.ClearLods();
                mProgressMesh.PushLod(0.97f);
                mProgressMesh.PushLod(0.93f);
                mProgressMesh.PushLod(0.9f);
                mProgressMesh.PushLod(0.87f);
                mProgressMesh.PushLod(0.83f);
                mProgressMesh.PushLod(0.8f);
                mProgressMesh.PushLod(0.75f);
                mProgressMesh.PushLod(0.7f);
                mProgressMesh.PushLod(0.6f);
                mProgressMesh.PushLod(0.5f);
                mProgressMesh.PushLod(0.3f);
                mProgressMesh.PushLod(0.1f);
                mProgressMesh.PushLod(0.0f);
            }

            await InitUIDrawer();
        }
Exemplo n.º 4
0
        public override async Task <bool> SetInitializer(CRenderContext rc, GActor host, GComponentInitializer v)
        {
            if (await base.SetInitializer(rc, host, v) == false)
            {
                return(false);
            }

            mMeshComponent = new GamePlay.Component.GMeshComponent();
            var meshCompInit = new GamePlay.Component.GMeshComponent.GMeshComponentInitializer();

            meshCompInit.SpecialName = "VisualMesh";
            meshCompInit.MeshName    = RName.GetRName("editor/icon/icon_3D/mesh/play_start.gms", RName.enRNameType.Game);
            await mMeshComponent.SetInitializer(rc, Host, meshCompInit);

            //var mat = host.Placement.WorldMatrix;
            //mMeshComponent.OnUpdateDrawMatrix(ref mat);

            Initializer = v as AgentGeomBoxComponentInitializer;
            if (Initializer != null)
            {
                AgentGridSize = Initializer.AgentGridSize;
                StartPos      = Initializer.StartPos;
            }
            else
            {
                Initializer = new AgentGeomBoxComponentInitializer();
            }

            return(true);
        }
Exemplo n.º 5
0
        public override async Task <bool> LoadXnd(CRenderContext rc, GActor host, IComponentContainer hostContainer, XndNode node)
        {
            Host = host;
            if (false == await base.LoadXnd(rc, host, hostContainer, node))
            {
                return(false);
            }

            var cpNodes = node.FindNode("CompChildren");

            if (cpNodes != null)
            {
                Components.Clear();
                var nodes = cpNodes.GetNodes();
                foreach (var i in nodes)
                {
                    var type = Rtti.RttiHelper.GetTypeFromSaveString(i.GetName());
                    if (type == null)
                    {
                        Profiler.Log.WriteLine(Profiler.ELogTag.Error, "ACC", $"Component {i.GetName()} is invalid");
                        continue;
                    }
                    Component.GComponent comp = Activator.CreateInstance(type) as Component.GComponent;
                    if (false == await comp.LoadXnd(rc, Host, this, i))
                    {
                        Profiler.Log.WriteLine(Profiler.ELogTag.Error, "ACC", $"Component {i.GetName()} load failed");
                        continue;
                    }
                    this.AddComponent(comp);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public async Task <GComponent> CreateComponent(IComponentContainer componentContainer)
        {
            GActor hostActor = null;
            IComponentContainer hostContainer = null;

            if (componentContainer is GActor)
            {
                hostActor     = componentContainer as GActor;
                hostContainer = componentContainer;
            }
            else if (componentContainer is GComponent)
            {
                hostActor     = (componentContainer as GComponent).Host;
                hostContainer = componentContainer;
            }
            var rc   = CEngine.Instance.RenderContext;
            var comp = new GMeshComponent();
            var init = new GMeshComponent.GMeshComponentInitializer();

            init.MeshName = ResourceName;
            await comp.SetInitializer(rc, hostActor, hostContainer, init);

            comp.SpecialName = ResourceName.PureName();
            return(comp);
        }
Exemplo n.º 7
0
        public async System.Threading.Tasks.Task <bool> PreViewSimMeshAsync(CSimGeom simgeom)
        {
            if (simgeom.MaxVertices == 0)
            {
                MessageBox.Show("MaxVertices is Null error");
                return(false);
            }

            return(await CEngine.Instance.EventPoster.Post(() =>
            {
                if (simgeom.IsChange)
                {
                    simgeom.IsChange = false;
                    //var test = BuildTriMeshAsync();
                    simgeom.BuildTriMesh(CEngine.Instance.RenderContext, simgeom.Mesh.MeshPrimitives, ref simgeom.CCDD);
                    simgeom.MeshPrimitives = simgeom.CreateMesh(CEngine.Instance.RenderContext);
                }
                if (simgeom.MeshPrimitives != null)
                {
                    GActor actor = NewMeshActor(CEngine.Instance.MeshManager.CreateMesh(CEngine.Instance.RenderContext, simgeom.MeshPrimitives));
                    actor.Placement.SetMatrix(ref mPreviewActor.Placement.mDrawTransform);
                    var test = actor.GetComponent <EngineNS.GamePlay.Component.GMeshComponent>().SetMaterialInstanceAsync(CEngine.Instance.RenderContext, 0, CEngine.Instance.MaterialInstanceManager.DefaultMaterialInstance, null);
                    mPreviewSceneControl.AddUniqueActor(actor);
                }
                return true;
            }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor));//, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor)
        }
Exemplo n.º 8
0
 protected override bool SetCondition(GActor pa)
 {
     if (!pa.GetComponent <CAgentComponent>())
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 9
0
    public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position)
    {
        // Do not allow editing palettes
        if (brushTarget.layer == 31 || brushTarget == null)
        {
            return;
        }

        var objectsInCell           = GetObjectsInCell(grid, brushTarget.transform, position);
        var existPrefabObjectInCell = objectsInCell.Any(objectInCell =>
        {
            return(m_Prefabs.Any(prefab => PrefabUtility.GetCorrespondingObjectFromSource(objectInCell) == prefab));
        });

        if (!existPrefabObjectInCell)
        {
            int index = -1;
            if (probability.Length == 0)
            {
                index = Mathf.Clamp(Mathf.FloorToInt(GetPerlinValue(position, m_PerlinScale, k_PerlinOffset) * m_Prefabs.Length), 0, m_Prefabs.Length - 1);
            }
            else if (probability.Length == m_Prefabs.Length)
            {
                float rand = GetPerlinValue(position, m_PerlinScale, k_PerlinOffset);
                float sum  = 0;
                foreach (float x in probability)
                {
                    sum += x;
                }
                rand *= sum;
                sum   = 0;
                for (int i = 0; i < probability.Length; i++)
                {
                    sum += probability[i];
                    if (rand < sum)
                    {
                        index = i;
                        break;
                    }
                }
            }
            else
            {
                Debug.LogError("概率数量与预制体数量不匹配");
            }
            var    prefab   = m_Prefabs[index];
            var    instance = base.InstantiatePrefabInCell(grid, brushTarget, position, prefab);
            GActor actor    = instance.GetComponent <GActor>();
            if (actor == null)
            {
                Debug.LogError("非GActor");
            }
            else
            {
                actor.location = new Vector2Int(position.x, position.y);
            }
        }
    }
Exemplo n.º 10
0
 /*
  *  Function: moveObjToSector
  *
  *  Parameters: GActor:<obj>, WorldSector:<sector>
  *
  *  Returns: void
  *
  *  -Places the reference for <obj> into <sector>.
  *  -If <obj>s reference is already contained by another sector, it is first removed from the old sector.
  *  -The reference to <obj> is stored in <sector>s <Contained_Objects> property.
  *  -Since only GActors are stored in sectors, <obj> must be of type GActor. All other GObjects are stored in tiles.
  */
 public void moveObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector != null)
     {
         // object belongs to a sector
         removeObjFromSector(obj);
     }
     addObjToSector(obj, sector);
 }
Exemplo n.º 11
0
 void addObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector == null)
     {
         // object does not belong to a sector
         obj.sector = sector;
         sector.Contained_Objects.addObject(obj);
     }
 }
Exemplo n.º 12
0
 void removeObjFromSector(GActor obj)
 {
     if (obj.sector != null)
     {
         // object belongs to a sector
         obj.sector.Contained_Objects.removeObject(obj);
         obj.sector = null;
     }
 }
Exemplo n.º 13
0
 public override void OnActorLoaded(GActor actor)
 {
     base.OnActorLoaded(actor);
     for (int i = 0; i < Components.Count; ++i)
     {
         var comp = Components[i];
         comp.OnActorLoaded(actor);
     }
 }
Exemplo n.º 14
0
 protected override bool SetCondition(GActor pa)
 {
     if (!GridExtensions.InRange(GetRange(), pa.location))
     {
         Debug.Log("OutRange");
         return(false);
     }
     return(true);
 }
Exemplo n.º 15
0
 public bool objectIsContained(GActor obj)
 {
     for (int i = 0; i < all.count(); ++i)
     {
         if (all.getObjectAt(i) == obj)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 16
0
    public void addObject(GActor obj)
    {
        obj.reflist_index.all = all.count();
        all.addObject(obj);

        obj.reflist_index.environmental = environmental[(int)obj.properties.environmental].count();
        environmental [(int)obj.properties.environmental].addObject(obj);

        obj.reflist_index.NPCs = NPCs[(int)obj.properties.npc].count();
        NPCs [(int)obj.properties.npc].addObject(obj);
    }
Exemplo n.º 17
0
        public override async Task <bool> SetInitializer(CRenderContext rc, GActor host, GComponentInitializer v)
        {
            if (!await base.SetInitializer(rc, host, v))
            {
                return(false);
            }

            host.IsNavgation = true;

            return(true);
        }
Exemplo n.º 18
0
    void Start()
    {
        GActor self = GetComponent <GActor>();

        if (levelNumber >= 0 && self && self.location == targetLocation)
        {
            Instantiate(PrefabManager.instance.buildingParticle,
                        transform.position + PrefabManager.instance.buildingParticle.transform.position,
                        PrefabManager.instance.buildingParticle.transform.rotation);
            this.InvokeAfter(() => LevelManager.instance.SwitchToLevel(levelNumber), 1f);
        }
    }
Exemplo n.º 19
0
    public void removeObject(GObject obj)
    {
        GActor act = obj as GActor;

        if (act != null)
        {
            actors.removeObject(act);
        }
        else
        {
            Debug.LogError("Invalid GObject type");
        }
    }
Exemplo n.º 20
0
 private void performActorBehaviours()       // to be moved to ai section
 {
     for (int i = 0; i < sectorsWithinRange.Count; ++i)
     {
         for (int j = 0; j < sectorsWithinRange[i].Contained_Objects.actors.all.count(); ++j)
         {
             GActor actor = sectorsWithinRange[i].Contained_Objects.actors.all.getObjectAt(j);
             if (!actor.idle)
             {
                 actor.performBehaviour();
             }
         }
     }
 }
Exemplo n.º 21
0
    public bool objectIsContained(GObject obj)
    {
        GActor act = obj as GActor;

        if (act != null)
        {
            return(actors.objectIsContained(act));
        }
        else
        {
            Debug.LogError("Invalid GObject type");
        }
        return(false);
    }
Exemplo n.º 22
0
        void CreatePreviewMeshesActor(CGfxMesh mesh)
        {
            if (mesh == null)
            {
                return;
            }
            mPreviewActor = NewMeshActor(mesh);
            mPreviewActor.Placement.Location = new EngineNS.Vector3(0.0f, 0.0f, 0.0f);
            mPreviewSceneControl.AddUniqueActor(mPreviewActor);

            mPreviewActor.GetComponentMesh(null).SetPassUserFlags(1);

            var nu = InitUIDrawer();
        }
Exemplo n.º 23
0
 public CommandTask(GActor obj, Delegate action, Func <int, object[], bool> _checker = null)
 {
     task       = action;
     castObject = obj;
     ParameterInfo[] t = action.GetMethodInfo().GetParameters();
     types = new Type[t.Length];
     for (int i = 0; i < t.Length; i++)
     {
         types[i] = t[i].ParameterType;
     }
     //types =action.GetType().GetGenericArguments();
     parameters = new object[types.Length];
     curID      = 0;
     RefreshInputMode();
     checker = _checker;
 }
Exemplo n.º 24
0
    void OnClickActor(GActor target)
    {
        switch (target)
        {
        case GChess chess:
            eClickChess.Invoke(chess);
            eClickActor.Invoke(chess);
            eSelectMessage.Invoke(chess);
            break;

        case GFloor floor:
            eClickFloor.Invoke(floor);
            eClickActor.Invoke(floor);
            eSelectMessage.Invoke(floor);
            break;
        }
    }
Exemplo n.º 25
0
    private void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        // Casts the ray and get the first game object hit
        bool             bHit             = Physics.Raycast(ray, out hit);
        PointerEventData pointerEventData = new PointerEventData(eventSystem);

        //Set the Pointer Event Position to that of the mouse position
        pointerEventData.position = Input.mousePosition;

        //Create a list of Raycast Results
        List <RaycastResult> results = new List <RaycastResult>();

        //Raycast using the Graphics Raycaster and mouse click position
        raycaster.Raycast(pointerEventData, results);

        bool   isInteractingWithUI = results.Count > 0;
        GActor hitResult           = null;

        if (bHit && !isInteractingWithUI)
        {
            hitResult = hit.transform.gameObject.GetComponent <GActor>();
        }
        Vector2Int hitTile = new Vector2Int(0, -1);

        if (hitResult)
        {
            hitTile = hitResult.location;
        }
        if (hitTile != curTile)
        {
            curTile = hitTile;
            eOverTile.Invoke(hitTile);
        }

        if (Input.GetMouseButtonDown(0) && bHit)
        {
            OnClickActor(hitResult);
        }
        if (Input.GetMouseButtonDown(1))
        {
            eRightMouseClick.Invoke();
            eSelectMessage.Invoke(null);
        }
    }
Exemplo n.º 26
0
    private void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        // Casts the ray and get the first game object hit
        bool bHit = Physics.Raycast(ray, out hit);

        GActor hitResult = null;

        if (bHit)
        {
            hitResult = hit.transform.gameObject.GetComponent <GActor>();
        }
        Vector2Int hitTile = new Vector2Int(0, -1);

        if (hitResult)
        {
            hitTile = hitResult.location;
        }
        if (hitTile != curTile)
        {
            curTile = hitTile;
            eOverTile.Invoke(hitTile);
        }

        if (Input.GetMouseButtonDown(0) && bHit)
        {
            switch (hitResult)
            {
            case GChess chess:
                eClickChess.Invoke(chess);
                break;

            case GFloor floor:
                eClickFloor.Invoke(floor);
                break;
            }
        }
        if (Input.GetMouseButtonDown(1))
        {
            eRightMouseClick.Invoke();
        }
    }
Exemplo n.º 27
0
 protected virtual void SetParameters(GActor pa)
 {
     if (bPaused)
     {
         return;
     }
     if (checker?.Invoke(curID, pa) == false)
     {
         return;
     }
     if (!SetCondition(pa))
     {
         return;
     }
     parameters[curID++] = pa;
     RefreshInputMode();
     if (curID >= paramsCount)
     {
         Finish();
     }
 }
Exemplo n.º 28
0
        public void SetCameraByActor(GActor actor)
        {
            if (actor == null)
            {
                return;
            }
            var cameraComp = actor.GetComponentRecursion <GamePlay.Camera.CameraComponent>();

            if (cameraComp != null)
            {
                GameCamera = cameraComp.Camera;
                return;
            }
            var camera = actor.GetComponentRecursion <GamePlay.Camera.GCameraComponent>();

            if (camera != null)
            {
                GameCamera = camera.Camera.Camera;
                return;
            }
        }
Exemplo n.º 29
0
        void MoveActorToDefaultSceneNode(GamePlay.SceneGraph.ISceneNode node)
        {
            if (node == null)
            {
                return;
            }
            var it = node.Actors.GetEnumerator();

            while (it.MoveNext())
            {
                var    act   = it.Current;
                GActor actor = act.Value;
                Host.Scene.DefaultSceneNode.AddActor(actor);
            }
            it.Dispose();

            foreach (var child in node.ChildrenNode)
            {
                MoveActorToDefaultSceneNode(child);
            }
        }
Exemplo n.º 30
0
        public async Task <GComponent> CreateComponent(IComponentContainer componentContainer)
        {
            GActor hostActor = null;
            IComponentContainer hostContainer = null;

            if (componentContainer is GActor)
            {
                hostActor     = componentContainer as GActor;
                hostContainer = componentContainer;
            }
            else if (componentContainer is GComponent)
            {
                hostActor     = (componentContainer as GComponent).Host;
                hostContainer = componentContainer;
            }
            var rc   = CEngine.Instance.RenderContext;
            var comp = new GParticleComponent();

            comp.ResetMacross(ResourceName);
            comp.SpecialName = ResourceName.PureName();
            return(comp);
        }
Exemplo n.º 31
0
	public void linkActor(GActor act, ObjectAnimController anim_controller) {
		actor = act;
		animController = anim_controller;
	}
Exemplo n.º 32
0
	public void linkActor(GActor act) {
		actor = act;
	}
Exemplo n.º 33
0
 void addObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector == null) {
         // object does not belong to a sector
         obj.sector = sector;
         sector.Contained_Objects.addObject(obj);
     }
 }
Exemplo n.º 34
0
 void removeObjFromSector(GActor obj)
 {
     if (obj.sector != null) {
         // object belongs to a sector
         obj.sector.Contained_Objects.removeObject(obj);
         obj.sector = null;
     }
 }
Exemplo n.º 35
0
 /*
  *  Function: moveObjToSector
  *
  *  Parameters: GActor:<obj>, WorldSector:<sector>
  *
  * 	Returns: void
  *
  * 	-Places the reference for <obj> into <sector>.
  *  -If <obj>s reference is already contained by another sector, it is first removed from the old sector.
  *  -The reference to <obj> is stored in <sector>s <Contained_Objects> property.
  *  -Since only GActors are stored in sectors, <obj> must be of type GActor. All other GObjects are stored in tiles.
  */
 public void moveObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector != null) {
         // object belongs to a sector
         removeObjFromSector(obj);
     }
     addObjToSector (obj, sector);
 }