Exemplo n.º 1
0
    public void LoadAsset()
    {
        CAsset asset = null;

        if (mType == EAssetType.AT_BRUSH)
        {
            asset = new CBrushAsset();
        }
        else if (mType == EAssetType.AT_MODEL)
        {
            asset = new CModelAsset();
        }
        else if (mType == EAssetType.AT_LEVEL)
        {
            asset = new CLevelAsset();
        }
        else if (mType == EAssetType.AT_ITEM)
        {
            asset = new CItemAsset();
        }

        if (asset != null)
        {
            asset.mName     = mName;
            asset.mFileName = mFileName;
            asset.mType     = mType;
            asset.Load();
            mAsset = asset;
        }
        else
        {
            Debug.LogError("Could not load asset: " + mName);
        }
    }
Exemplo n.º 2
0
    private void _RenderItemIcon(Rect ViewportRect, CItemAsset Item)
    {
        GL.Viewport(ViewportRect);
        //GL.Clear(true, true, new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value, 1.0f));

        Matrix4x4 projMat = Matrix4x4.Perspective(5.0f, 1, 1.0f, 100.0f);

        Matrix4x4 viewMat = Matrix4x4.TRS(new Vector3(Item.mIconCameraPostion.x, Item.mIconCameraPostion.y, Item.mIconCameraPostion.z - 30), Quaternion.identity, Vector3.one);

        viewMat *= Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.AngleAxis(-40.0f, Vector3.left), Vector3.one);
        viewMat *= Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.AngleAxis(225.0f, Vector3.up), Vector3.one);

        Matrix4x4 viewProjMat = projMat * viewMat;

        if (Item.mPMAsset != null)
        {
            Mesh      m        = Item.mPMAsset.mVectorModel.GetSharedMesh(EViewDirection.VD_FRONT);
            Matrix4x4 modelMat = Matrix4x4.TRS(Item.mPMPosition, Quaternion.Euler(Item.mPMRotation), Vector3.one);

            CGame.PrimaryResources.VecMat.SetMatrix("worldMat", viewProjMat * modelMat);
            CGame.PrimaryResources.VecMat.SetPass(0);
            Graphics.DrawMeshNow(m, Matrix4x4.zero);
        }

        if (Item.mSMAsset != null)
        {
            Mesh      m        = Item.mSMAsset.mVectorModel.GetSharedMesh(EViewDirection.VD_FRONT);
            Matrix4x4 modelMat = Matrix4x4.TRS(Item.mSMPosition, Quaternion.Euler(Item.mSMRotation), Vector3.one);

            CGame.PrimaryResources.VecMat.SetMatrix("worldMat", viewProjMat * modelMat);
            CGame.PrimaryResources.VecMat.SetPass(0);
            Graphics.DrawMeshNow(m, Matrix4x4.zero);
        }
    }
Exemplo n.º 3
0
 public void CopyInitialState(CItemProxy ItemProxy)
 {
     mAsset     = ItemProxy.mAsset;
     mProxyID   = ItemProxy.mID;
     mItemID    = ItemProxy.mItemID;
     mBlueprint = ItemProxy.mBlueprint;
     //_targetSurfaceColor = ItemProxy.mSurfaceColor;
     _currentSurfaceColor = ItemProxy.mSurfaceColor;
 }
Exemplo n.º 4
0
    public void Init(int PlayerID, CItem Item, CWorld World, bool Blueprint)
    {
        if (PlayerID == -1)
        {
            Debug.LogError("CItemProxy should never have a playerID of -1!");
        }

        mID                   = GetNextID();
        mItemID               = Item.mID;
        mState                = EState.S_VISIBLE;
        mPlayerID             = PlayerID;
        mWorld                = World;
        _item                 = Item;
        mBlueprint            = Blueprint;
        mAsset                = Item.mAsset;
        mDurability           = Item.mDurability;
        mMaxDurability        = Item.mMaxDurability;
        mQueueList            = new List <CQueueToken>();
        mPosition             = Item.mPosition;
        mRotation             = Item.mItemRot;
        mBounds               = Item.mBounds;
        mOwnerID              = Item.mOwner;
        mAssignedPaperStacks  = new List <CContractStack>();
        mPaperStackUpdateTick = 0;
        mAssignedUnitID       = -1;

        mSurfaceColor = mWorld.mMap.mBackgroundColor;
        mBounds       = CItem.CalculateBounds(mPosition, mRotation, mAsset.mWidth, mAsset.mLength);

        if (!mBlueprint)
        {
            ModifyLocalCollisionMap(true);

            if (Item.mType == CEntity.EType.ITEM_DOOR)
            {
                mLocked = true;

                if (mWorld.IsAllied(Item.mOwner, PlayerID))
                {
                    mLocked = ((CItemDoor)Item).mLocked;
                }

                DoorModifyLocalCollisionMap(mLocked);
            }
            else if (Item.mType == CEntity.EType.ITEM_SAFE)
            {
                mValue = ((CItemSafe)Item).mValue;
            }
            else if (Item.mType == CEntity.EType.ITEM_DESK)
            {
                mMaxPaperStackSlots = ((CItemDesk)Item).mMaxPaperStackSlots;
            }
        }

        SetVisible();
        UpdateState(Item);
    }
    public CEntityPlacer(string AssetName, Transform Parent, PlacementDelegate PlacementDelegate)
    {
        mAsset = CGame.AssetManager.GetAsset <CItemAsset>(AssetName);
        if (mAsset == null)
        {
            Debug.LogError("Can't asset to place: " + AssetName);
            return;
        }

        _Init(EPlaceType.ITEM, Parent, PlacementDelegate);
    }
Exemplo n.º 6
0
    private void _OnClickCreateNewAssetWindow(GameObject Window, EAssetType Type, string AssetName)
    {
        string errorStr;

        if (CGame.AssetManager.IsAssetNameValid(AssetName, out errorStr))
        {
            GameObject.Destroy(Window);

            CTUITreeViewItem treeItem = null;
            CAsset           asset    = null;

            if (Type == EAssetType.AT_MODEL)
            {
                treeItem = _tviModels;
                asset    = new CModelAsset();
            }
            else if (Type == EAssetType.AT_BRUSH)
            {
                treeItem = _tviBrushes;
                asset    = new CBrushAsset();
            }
            else if (Type == EAssetType.AT_LEVEL)
            {
                treeItem = _tviLevels;
                asset    = new CLevelAsset();
            }
            else if (Type == EAssetType.AT_ITEM)
            {
                treeItem = _tviItems;
                asset    = new CItemAsset();
            }

            asset.mName     = AssetName;
            asset.mFileName = CGame.DataDirectory + asset.mName + "." + CAssetManager.ASSET_FILE_EXTENSION;
            Debug.Log("New Asset Path: " + asset.mFileName);
            asset.Save();

            CAssetDeclaration decl = CGame.AssetManager.CreateAssetDeclaration(asset);
            treeItem.AddItem(decl.mName, () => OnClickAsset(decl.mName), () => mToolkit.EditAsset(decl.mName));

            treeItem.RebuildEntireTree();
            mToolkit.EditAsset(AssetName);
        }
        else
        {
            Debug.Log("Asset creation failed: " + errorStr);
        }
    }
Exemplo n.º 7
0
    public virtual void InitItem(CAsset Asset)
    {
        mAsset = (CItemAsset)Asset;

        mWidth         = mAsset.mWidth;
        mLength        = mAsset.mLength;
        mOffsetX       = 0;
        mOffsetY       = 0;
        mDurability    = mAsset.mDurability;
        mMaxDurability = mDurability;
        mCost          = mAsset.mCost;

        /*
         * _usageSlotDefinition = new CEntryPoint[mDefinition.mSlots];
         * for (int i = 0; i < mDefinition.mSlots; ++i)
         * {
         *      _usageSlotDefinition[i] = new CEntryPoint();
         *      _usageSlotDefinition[i].mPosition = new Vector2(mDefinition.mSlotTransform[i].x, mDefinition.mSlotTransform[i].y);
         *      _usageSlotDefinition[i].mRotation = (int)mDefinition.mSlotTransform[i].z;
         * }
         */
    }
Exemplo n.º 8
0
    public static bool IsPlaceable(CWorld World, int PlayerID, CItemAsset Asset, int X, int Y, int Rotation)
    {
        // Check for collision with other blueprints
        Bounds bounds = CItem.CalculateBounds(new Vector2(X, Y), Rotation, Asset.mWidth, Asset.mLength);

        bounds.max -= new Vector3(0.1f, 0.1f, 0.1f);
        bounds.min += new Vector3(0.1f, 0.1f, 0.1f);

        for (int i = 0; i < World.mBlueprints.Count; ++i)
        {
            CItem b = World.mBlueprints[i];
            if (b.mOwner == PlayerID && b.mBluerprint)
            {
                if (b.mBounds.Intersects(bounds))
                {
                    return(false);
                }
            }
        }

        return(IsPlaceable(World.mMap.mTiles, World.mMap.mGlobalCollisionTiles, Asset, X, Y, Rotation));
    }
Exemplo n.º 9
0
    public static bool IsPlaceable(CUserWorldView WorldView, CItemAsset Asset, int X, int Y, int Rotation)
    {
        // Check for collision with other blueprints
        Bounds bounds = CItem.CalculateBounds(new Vector2(X, Y), Rotation, Asset.mWidth, Asset.mLength);

        bounds.max -= new Vector3(0.1f, 0.1f, 0.1f);
        bounds.min += new Vector3(0.1f, 0.1f, 0.1f);

        for (int i = 0; i < WorldView.mStateViews.Count; ++i)
        {
            CItemView v = WorldView.mStateViews[i] as CItemView;
            if (v != null && v.mBlueprint)
            {
                if (v.mBounds.Intersects(bounds))
                {
                    return(false);
                }
            }
        }

        return(IsPlaceable(WorldView.GetTileView(), WorldView.GetCollisionView(), Asset, X, Y, Rotation));
    }
Exemplo n.º 10
0
 public void SetDetails(CItemAsset Asset)
 {
     _asset = Asset;
 }
Exemplo n.º 11
0
    // Cell types:
    // Rather have flags or just more complex cell structure?
    // free - no effect
    // solid - full block solid for interaction
    // low - low block for interaction
    // select - can be selected but is not solid to units
    // entryN - represents a tile that leads to a usage node on the item

    // Item interaction is per polygon, so solid/low etc only for combat projectiles?
    // Collision objects for projectiles, particles?

    // Usage slot:
    // Determines if a unit is using the item.
    // Describes where a unit should be visually.
    // Turn into general attach node?

    public CItemEditor(string AssetName)
    {
        mAssetName = AssetName;
        _asset     = CGame.AssetManager.GetAsset <CItemAsset>(AssetName);
    }
Exemplo n.º 12
0
    public static bool IsPlaceable(CTile[,] MapTiles, CCollisionTile[,] CollisionTiles, CItemAsset Asset, int X, int Y, int Rotation)
    {
        // Do a world space run of the asset to check if tiles are unoccupied.
        Vector2 p1     = CItem.PivotRelativeToTile[Rotation];
        Vector2 size   = CItem.RotationAxisTable[Rotation].Transform(new Vector2(Asset.mWidth, Asset.mLength));
        Vector2 p2     = p1 + size;
        int     startX = ((int)Mathf.Min(p1.x, p2.x) + X) * 2;
        int     startY = ((int)Mathf.Min(p1.y, p2.y) + Y) * 2;
        int     width  = (int)Mathf.Abs(size.x) * 2;
        int     length = (int)Mathf.Abs(size.y) * 2;

        for (int iX = 0; iX < width; ++iX)
        {
            for (int iY = 0; iY < length; ++iY)
            {
                int worldX = iX + startX;
                int worldY = iY + startY;

                if (CollisionTiles[worldX, worldY].IsOccupied)
                {
                    return(false);
                }

                if (iY > 0 && CollisionTiles[worldX, worldY].mWallXSolid)
                {
                    return(false);
                }

                if (iX > 0 && CollisionTiles[worldX, worldY].mWallZSolid)
                {
                    return(false);
                }
            }
        }

        // Doors must be placed within frames.
        if (Asset.mItemType == EItemType.DOOR)
        {
            // Get core tile
            if (Rotation == 0 && MapTiles[X, Y + 1].mWallX.mType >= 100)
            {
                return(true);
            }
            else if (Rotation == 1 && MapTiles[X, Y].mWallZ.mType >= 100)
            {
                return(true);
            }
            else if (Rotation == 2 && MapTiles[X, Y].mWallX.mType >= 100)
            {
                return(true);
            }
            else if (Rotation == 3 && MapTiles[X + 1, Y].mWallZ.mType >= 100)
            {
                return(true);
            }

            return(false);
        }

        return(true);
    }
Exemplo n.º 13
0
 public void CopyInitialState(CPickup Pickup)
 {
     mID = Pickup.mID;
     mContainedItemAsset = Pickup.mContainedItemAsset;
 }