Inheritance: NetworkBehaviour
コード例 #1
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void CastRay(NewGameUnit unit, bool isMinimap, Vector3 mousePosition, Camera minimapCamera)
        {
            Ray ray;

            if (isMinimap)
            {
                ray = this.minimapCamera.ViewportPointToRay(mousePosition);
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(mousePosition);
            }
            RaycastHit[] hits = Physics.RaycastAll(ray, 500f);
            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject.tag.Equals("Floor"))
                {
                    this.changes = unit.CurrentProperty();
                    this.changes.mousePosition = hit.point;
                    this.changes.isCommanded   = true;
                    CmdUpdateUnitProperty(unit.gameObject, this.changes);
                    break;
                }
            }
        }
コード例 #2
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void CheckAvailableResource()
        {
            //NOTE(Thompson): In this game, LV1 game units are resources. Splitting is
            //only available to LV1 game units, so without LV1 game units, the player is
            //doomed to fail.

            int levelOneUnitCount         = 0;
            int selectedLevelOneUnitCount = 0;

            for (int i = 0; i < this.unitList.Count; i++)
            {
                NewGameUnit unit = this.unitList[i].unit.GetComponent <NewGameUnit>();
                if (unit != null && unit.properties.level == 1)
                {
                    levelOneUnitCount++;
                }
            }
            for (int i = 0; i < this.selectedList.Count; i++)
            {
                NewGameUnit unit = this.selectedList[i].unit.GetComponent <NewGameUnit>();
                if (unit != null && unit.properties.level == 1 && unit.properties.isSelected)
                {
                    selectedLevelOneUnitCount++;
                }
            }
            if (selectedLevelOneUnitCount <= 2)
            {
                if (selectedLevelOneUnitCount == levelOneUnitCount || levelOneUnitCount <= 2)
                {
                    this.doNotAllowMerging = true;
                }
            }
        }
コード例 #3
0
 public void CmdDestroy(GameObject targetUnit)
 {
     if (targetUnit != null)
     {
         NewGameUnit unit = targetUnit.GetComponent <NewGameUnit>();
         if (unit != null && NetworkServer.FindLocalObject(unit.netId))
         {
             if (targetUnit != null)
             {
                 NewChanges changes = unit.CurrentProperty();
                 if (changes.targetUnit != null && changes.targetUnit.Equals(this.gameObject))
                 {
                     changes.targetUnit = null;
                     unit.NewProperty(changes);
                 }
             }
             NewLOS los = this.GetComponentInChildren <NewLOS>();
             if (los != null)
             {
                 los.parent = null;
             }
             NewAtkRange range = this.GetComponentInChildren <NewAtkRange>();
             if (range != null)
             {
                 range.parent = null;
             }
             NetworkServer.Destroy(this.gameObject);
         }
     }
 }
コード例 #4
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 private void TempRectSelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         if (temp.unit == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         Vector3 projectedPosition = Camera.main.WorldToScreenPoint(temp.unit.transform.position);
         projectedPosition.y = Screen.height - projectedPosition.y;
         if (this.selectionBox.Contains(projectedPosition))
         {
             NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>();
             if (unit.properties.isSelected || !unit.hasAuthority)
             {
                 continue;
             }
             if (temp.unit == null)
             {
                 CmdRemoveUnitList(this.unitList[i].unit);
                 continue;
             }
             this.changes            = unit.CurrentProperty();
             this.changes.isSelected = true;
             CmdUpdateUnitProperty(unit.gameObject, this.changes);
         }
         else
         {
             continue;
         }
     }
 }
コード例 #5
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        public void RpcFilter(NetworkInstanceId unitID, NetworkInstanceId spawnerID)
        {
            //NOTE(Thompson): This organizes the Hierarchy in Unity, so player units are children of player owned NewSpawners.
            GameObject obj           = ClientScene.FindLocalObject(unitID);
            GameObject spawnerObject = ClientScene.FindLocalObject(spawnerID);

            obj.transform.SetParent(spawnerObject.transform);
            NewGameUnit unit = obj.GetComponent <NewGameUnit>();

            if (unit.hasAuthority)
            {
                unit.SetTeamColor(unit.properties.teamColor);                 //NOTE(Thompson): This has to do with triggering the SyncVar's hook.
                Vector3 pos = obj.transform.position;
                pos.y  = Camera.main.transform.position.y;
                pos.z -= 5f;
                Camera.main.transform.position = pos;
            }

            NewGameUnit[] units    = GameObject.FindObjectsOfType <NewGameUnit>();
            NewSpawner[]  spawners = GameObject.FindObjectsOfType <NewSpawner>();
            for (int i = 0; i < units.Length; i++)
            {
                if (!units[i].hasAuthority)
                {
                    for (int j = 0; j < spawners.Length; j++)
                    {
                        if (!spawners[j].hasAuthority)
                        {
                            units[i].transform.SetParent(spawners[j].transform);
                            units[i].SetTeamColor(units[i].properties.teamColor);                             //NOTE(Thompson): This has to do with triggering the SyncVar's hook.
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void CmdAttack(bool hasAuthority, GameObject attacker, GameObject victim, int damage)
        {
            if (victim != null && attacker != null)
            {
                NewGameUnit victimUnit   = victim.GetComponent <NewGameUnit>();
                NewGameUnit attackerUnit = attacker.GetComponent <NewGameUnit>();
                if (!(NetworkServer.FindLocalObject(victimUnit.netId) || NetworkServer.FindLocalObject(attackerUnit.netId)))
                {
                    return;
                }
                if (victimUnit != null && attackerUnit != null && !attackerUnit.properties.isAttackCooldownEnabled && NetworkServer.FindLocalObject(victimUnit.netId) != null && NetworkServer.FindLocalObject(attackerUnit.netId) != null)
                {
                    NewChanges changes = victimUnit.CurrentProperty();
                    changes.damage            = damage;
                    changes.isRecoveryEnabled = true;
                    victimUnit.NewProperty(changes);
                    RpcTakeDamageColor(victimUnit.netId);

                    if (victimUnit.properties.currentHealth == 0 && attackerUnit.hasAuthority == hasAuthority)
                    {
                        //TODO(Thompson): See if removing the authority check helps fixing the kill counter being
                        //only the server side can take kill counts, while client side sometimes not taking kill counts.
                        attackerUnit.LogKill();
                    }
                }
            }
        }
コード例 #7
0
ファイル: NewAtkRange.cs プロジェクト: kyapp69/Multiplier
        public void OnTriggerEnter(Collider other)
        {
            NewGameUnit unit = other.gameObject.GetComponent <NewGameUnit>();

            if (unit != null && !unit.hasAuthority && unit.properties.teamFactionID != this.parent.properties.teamFactionID)
            {
                this.detectedUnits.Add(unit);
            }
        }
コード例 #8
0
        public void RpcSetDestination(GameObject obj, Vector3 pos)
        {
            NewGameUnit unit = obj.GetComponent <NewGameUnit>();

            if (unit != null && unit.agent != null)
            {
                unit.agent.SetDestination(pos);
            }
        }
コード例 #9
0
 public void CmdSetDestination(GameObject obj, Vector3 pos)
 {
     if (obj != null)
     {
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         if (unit != null)
         {
             RpcSetDestination(obj, pos);
         }
     }
 }
コード例 #10
0
 public void CmdUpdateProperty(GameObject obj, NewChanges changes)
 {
     if (obj != null)
     {
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         if (unit != null)
         {
             unit.NewProperty(changes);
         }
     }
 }
コード例 #11
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 public void CmdUpdateUnitProperty(GameObject unit, NewChanges changes)
 {
     if (unit != null)
     {
         NewGameUnit gameUnit = unit.GetComponent <NewGameUnit>();
         if (gameUnit != null)
         {
             gameUnit.NewProperty(changes);
         }
     }
 }
コード例 #12
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 public void RpcAddMerge(GameObject owner, GameObject merge, NewChanges changes)
 {
     if (owner != null && merge != null)
     {
         NewGameUnit ownerUnit = owner.GetComponent <NewGameUnit>();
         if (ownerUnit != null)
         {
             this.mergeList.Add(new Merge(owner.transform, merge.transform, ownerUnit.properties.scalingFactor));
         }
     }
 }
コード例 #13
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void SelectObjectAtPoint()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            foreach (RaycastHit hit in hits)
            {
                GameObject obj = hit.collider.gameObject;
                //NOTE(Thompson): If all fails, change "tag" to "name", and "Unit" to "NewGameUnit".
                //This is now fixed, so we have two options here.
                if (obj.tag.Equals("Unit"))
                {
                    NewUnitStruct temp = new NewUnitStruct(obj);
                    NewGameUnit   unit = temp.unit.GetComponent <NewGameUnit>();
                    if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                    {
                        if (this.unitList.Contains(temp) && unit.hasAuthority)
                        {
                            if (!this.selectedList.Contains(temp))
                            {
                                this.changes       = unit.CurrentProperty();
                                changes.isSelected = true;
                                unit.NewProperty(changes);
                                CmdUpdateUnitProperty(unit.gameObject, this.changes);
                                this.selectedList.Add(temp);
                            }
                            else if (this.selectedList.Contains(temp))
                            {
                                this.changes            = unit.CurrentProperty();
                                this.changes.isSelected = false;
                                unit.NewProperty(changes);
                                CmdUpdateUnitProperty(unit.gameObject, this.changes);
                                this.selectedList.Remove(temp);
                            }
                        }
                    }
                    else
                    {
                        if (unit != null && unit.hasAuthority)
                        {
                            this.changes       = unit.CurrentProperty();
                            changes.isSelected = true;
                            unit.NewProperty(changes);
                            CmdUpdateUnitProperty(unit.gameObject, this.changes);
                            this.selectedList.Add(temp);
                        }
                    }
                }
            }
        }
コード例 #14
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        public void CmdInitialize(GameObject spawner)
        {
            NetworkIdentity spawnerID = spawner.GetComponent <NetworkIdentity>();

            //Only the server choose what color values to use. Client values do not matter.
            int colorValue = NewSpawner.colorCode;

            NewSpawner.colorCode = (++NewSpawner.colorCode) % 3;
            Color color;

            switch (colorValue)
            {
            default:
                color = Color.gray;
                break;

            case 0:
                color = Color.yellow;
                break;

            case 1:
                color = Color.blue;
                break;

            case 2:
                color = Color.green;
                break;
            }


            GameObject gameUnit = MonoBehaviour.Instantiate <GameObject>(this.newGameUnitPrefab);

            gameUnit.name = gameUnit.name.Substring(0, gameUnit.name.Length - "(Clone)".Length);
            gameUnit.transform.SetParent(this.transform);
            gameUnit.transform.position = this.transform.position;
            NewGameUnit b       = gameUnit.GetComponent <NewGameUnit>();
            NewChanges  changes = b.CurrentProperty();

            if (!changes.isInitialized)
            {
                changes.isInitialized = false;
                changes.teamColor     = color;
                changes.teamFactionID = (int)(Random.value * 100f);                 //This is never to be changed.
            }
            b.NewProperty(changes);
            NetworkServer.SpawnWithClientAuthority(b.gameObject, spawnerID.clientAuthorityOwner);

            RpcAdd(gameUnit, spawner);
            RpcFilter(b.netId, spawnerID.netId);
        }
コード例 #15
0
ファイル: NewAtkRange.cs プロジェクト: kyapp69/Multiplier
        public void OnTriggerExit(Collider other)
        {
            NewGameUnit unit = other.GetComponent <NewGameUnit>();

            if (unit != null && !unit.hasAuthority && unit.properties.teamFactionID != this.parent.properties.teamFactionID)
            {
                this.detectedUnits.Remove(unit);
            }
            if (this.detectedUnits.Count <= 0)
            {
                NewChanges changes = this.parent.CurrentProperty();
                changes.enemyHitPosition = changes.mousePosition;
                this.parent.CallCmdupdateProperty(changes);
            }
        }
コード例 #16
0
        public void RpcTakeDamageColor(NetworkInstanceId victimNetID)
        {
            GameObject obj = ClientScene.FindLocalObject(victimNetID);

            if (obj != null)
            {
                NewGameUnit victimUnit = obj.GetComponent <NewGameUnit>();
                if (victimUnit != null)
                {
                    //NOTE(Thompson): This makes the victim (this game unit) show a visual indicator
                    //of it being attacked and taking damage.
                    victimUnit.takeDamageCounter = 1f;
                }
            }
        }
コード例 #17
0
 public void CmdRecover(GameObject recoveringObject, int healValue)
 {
     if (recoveringObject != null)
     {
         NewGameUnit unit = recoveringObject.GetComponent <NewGameUnit>();
         if (unit != null && NetworkServer.FindLocalObject(unit.netId))
         {
             if (unit.properties.currentHealth < unit.properties.maxHealth && unit.properties.isRecoveryEnabled)
             {
                 NewChanges changes = unit.CurrentProperty();
                 changes.heal = healValue;
                 unit.NewProperty(changes);
             }
         }
     }
 }
コード例 #18
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        public void CmdSplitSpawn(GameObject owner, NetworkIdentity ownerIdentity)
        {
            NewGameUnit unit    = owner.GetComponent <NewGameUnit>();
            NewChanges  changes = unit.CurrentProperty();

            changes.isSelected  = false;
            changes.isSplitting = true;
            changes.teamColor   = unit.GetTeamColor();
            unit.NewProperty(changes);
            GameObject split = MonoBehaviour.Instantiate <GameObject>(owner);

            split.name = "NewGameUnit";
            split.transform.SetParent(this.transform);
            split.transform.position = unit.transform.position;
            unit = split.GetComponent <NewGameUnit>();
            unit.NewProperty(changes);
            NetworkServer.SpawnWithClientAuthority(split, ownerIdentity.clientAuthorityOwner);
            RpcAddSplit(owner, split, changes, Random.Range(-180f, 180f));
            //this.splitList.Add(new Split(temp.transform, unit.transform));
            RpcOrganizeUnit(owner, split);
        }
コード例 #19
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 public void RpcAddSplit(GameObject owner, GameObject split, NewChanges changes, float angle)
 {
     if (owner != null && split != null)
     {
         NewGameUnit splitUnit = split.GetComponent <NewGameUnit>();
         if (splitUnit != null)
         {
             splitUnit.NewProperty(changes);
         }
         else
         {
             Debug.LogWarning("SplitUnit does not exist.");
         }
         this.splitList.Add(new Split(owner.transform, split.transform, angle));
     }
     else
     {
         string value1 = (owner == null) ? " Owner is null." : "";
         string value2 = (split == null) ? " Split is null." : "";
         Debug.LogWarning(value1 + value2);
     }
 }
コード例 #20
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 private void SelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         GameObject    obj  = temp.unit.gameObject;
         if (obj == null)
         {
             this.unitList.Remove(temp);
             continue;
         }
         if (this.selectedList.Contains(temp))
         {
             NewGameUnit unit = obj.GetComponent <NewGameUnit>();
             if (unit != null && unit.hasAuthority)
             {
                 this.changes       = unit.CurrentProperty();
                 changes.isSelected = true;
                 CmdUpdateUnitProperty(unit.gameObject, this.changes);
             }
         }
     }
 }
コード例 #21
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 private void ClearSelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         if (temp.unit == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         GameObject obj = temp.unit.gameObject;
         if (obj == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         changes            = unit.CurrentProperty();
         changes.isSelected = false;
         CmdUpdateUnitProperty(unit.gameObject, this.changes);
     }
     this.selectedList.Clear();
 }
コード例 #22
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void HandleSelection()
        {
            if (this.minimapCamera == null || !this.selectionBoxRenderer.enabled)
            {
                return;
            }

            //This handles all the input actions the player has done in the minimap.
            this.screenPoint = Camera.main.ScreenToViewportPoint(Input.mousePosition);
            if (this.minimapCamera.rect.Contains(this.screenPoint) && Input.GetMouseButtonDown(1))
            {
                if (this.selectedList.Count > 0)
                {
                    float   mainX = (this.screenPoint.x - this.minimapCamera.rect.xMin) / (1.0f - this.minimapCamera.rect.xMin);
                    float   mainY = (this.screenPoint.y) / (this.minimapCamera.rect.yMax);
                    Vector3 minimapScreenPoint = new Vector3(mainX, mainY, 0f);
                    foreach (NewUnitStruct temp in this.selectedList)
                    {
                        NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>();
                        if (unit != null)
                        {
                            CastRay(unit, true, minimapScreenPoint, this.minimapCamera);
                        }
                    }
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if (this.minimapCamera.rect.Contains(this.screenPoint))
                    {
                        return;
                    }
                    if (!(Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
                    {
                        ClearSelectObjects();
                    }
                    this.isSelecting  = true;
                    this.initialClick = Input.mousePosition;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    if (!(Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
                    {
                        ClearSelectObjects();
                    }
                    SelectObjectAtPoint();
                    SelectObjectsInRect();
                    SelectObjects();
                    this.isSelecting    = false;
                    this.isBoxSelecting = false;
                    this.initialClick   = -Vector3.one * 9999f;
                }
            }

            if (this.isSelecting && Input.GetMouseButton(0))
            {
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    this.isBoxSelecting = true;
                }
                this.selectionBox.Set(this.initialClick.x, Screen.height - this.initialClick.y, Input.mousePosition.x - this.initialClick.x, (Screen.height - Input.mousePosition.y) - (Screen.height - this.initialClick.y));
                if (this.selectionBox.width < 0)
                {
                    this.selectionBox.x     += this.selectionBox.width;
                    this.selectionBox.width *= -1f;
                }
                if (this.selectionBox.height < 0)
                {
                    this.selectionBox.y      += this.selectionBox.height;
                    this.selectionBox.height *= -1f;
                }
                TempRectSelectObjects();
            }
        }
コード例 #23
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        //-----------   Private class methods may all need refactoring   --------------------

        private void HandleInputs()
        {
            if (Input.GetKeyUp(KeyCode.S))
            {
                foreach (NewUnitStruct temp in this.selectedList)
                {
                    NewGameUnit newUnit = temp.unit.GetComponent <NewGameUnit>();
                    if (!newUnit.properties.isSplitting && this.unitList.Count < NewSpawner.MAX_UNIT_LIMIT && newUnit.properties.level == 1)
                    {
                        CmdSplitSpawn(temp.unit, temp.unit.GetComponent <NetworkIdentity>());
                    }
                    else
                    {
                        if (newUnit != null)
                        {
                            this.changes             = newUnit.CurrentProperty();
                            this.changes.isSelected  = false;
                            this.changes.isSplitting = false;
                            newUnit.NewProperty(this.changes);
                        }
                    }
                }
                this.selectedList.Clear();
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                NewGameUnit owner = null, merge = null;
                if (this.selectedList.Count == 1)
                {
                    owner                   = this.selectedList[0].unit.GetComponent <NewGameUnit>();
                    this.changes            = owner.CurrentProperty();
                    this.changes.isSelected = false;
                    owner.NewProperty(this.changes);
                }
                else
                {
                    for (int i = this.selectedList.Count - 1; i >= 1; i--)
                    {
                        owner = this.selectedList[i].unit.GetComponent <NewGameUnit>();
                        if (owner != null && !owner.properties.isMerging)
                        {
                            for (int j = i - 1; j >= 0; j--)
                            {
                                merge = this.selectedList[j].unit.GetComponent <NewGameUnit>();
                                this.doNotAllowMerging = false;
                                if (owner.properties.level == 1 && merge.properties.level == 1)
                                {
                                    CheckAvailableResource();
                                }
                                if (merge != null && !merge.properties.isMerging && merge.properties.level == owner.properties.level && !this.doNotAllowMerging)
                                {
                                    this.changes       = owner.CurrentProperty();
                                    changes.isMerging  = true;
                                    changes.isSelected = false;

                                    changes.newLevel++;
                                    changes.newMaxHealth      = this.unitAttributesManager.healthPrefabList[changes.newLevel];
                                    changes.newAttack         = this.unitAttributesManager.attackPrefabList[changes.newLevel];
                                    changes.newSpeed          = this.unitAttributesManager.speedPrefabList[changes.newLevel];
                                    changes.newSplit          = this.unitAttributesManager.splitPrefabFactor;
                                    changes.newMerge          = this.unitAttributesManager.mergePrefabList[changes.newLevel];
                                    changes.newAttackCooldown = this.unitAttributesManager.attackCooldownPrefabList[changes.newLevel];

                                    CmdUpdateUnitProperty(owner.gameObject, this.changes);
                                    CmdUpdateUnitProperty(merge.gameObject, this.changes);
                                    CmdMergeUpdate(owner.gameObject, merge.gameObject, this.changes);
                                    this.selectedList.RemoveAt(i);
                                    i--;
                                    this.selectedList.RemoveAt(j);
                                    j--;
                                    break;
                                }
                                else
                                {
                                    if (merge != null)
                                    {
                                        this.changes            = merge.CurrentProperty();
                                        this.changes.isSelected = false;
                                        this.changes.isMerging  = false;
                                        merge.NewProperty(this.changes);
                                        //this.selectedList.RemoveAt(j);
                                        //i--;
                                        //j--;
                                    }
                                }
                            }
                            if (merge == null)
                            {
                                this.changes            = owner.CurrentProperty();
                                this.changes.isSelected = false;
                                this.changes.isMerging  = false;
                                owner.NewProperty(this.changes);
                                //this.selectedList.RemoveAt(i);
                                //i--;
                            }
                        }
                        else if (owner != null)
                        {
                            this.changes            = owner.CurrentProperty();
                            this.changes.isSelected = false;
                            this.changes.isMerging  = false;
                            owner.NewProperty(this.changes);
                            //this.selectedList.RemoveAt(i);
                            //i--;
                        }
                    }
                }
            }
            if (Input.GetMouseButtonUp(1) && !this.minimapCamera.rect.Contains(this.screenPoint))
            {
                Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray);
                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.gameObject.tag.Equals("Floor"))
                    {
                        foreach (NewUnitStruct temp in this.selectedList)
                        {
                            if (temp.unit == null)
                            {
                                continue;
                            }
                            NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>();
                            this.changes = unit.CurrentProperty();
                            this.changes.mousePosition = hit.point;
                            this.changes.isCommanded   = true;
                            CmdUpdateUnitProperty(temp.unit, this.changes);
                        }
                    }
                }
            }
        }
コード例 #24
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void ManageNonAuthorityLists()
        {
            if (this.splitList.Count > 0)
            {
                for (int i = this.splitList.Count - 1; i >= 0; i--)
                {
                    Split splitGroup = this.splitList[i];
                    if (splitGroup.owner == null || splitGroup.split == null)
                    {
                        this.splitList.Remove(splitGroup);
                    }
                    if (splitGroup.elapsedTime > 1f)
                    {
                        NewGameUnit unit    = splitGroup.owner.GetComponent <NewGameUnit>();
                        NewChanges  changes = unit.CurrentProperty();
                        changes.isSelected  = false;
                        changes.isSplitting = false;
                        //CmdUpdateUnitProperty(splitGroup.owner.gameObject, changes);
                        unit.NewProperty(changes);
                        unit = splitGroup.split.GetComponent <NewGameUnit>();
                        unit.NewProperty(changes);
                        //CmdUpdateUnitProperty(splitGroup.split.gameObject, changes);
                        //this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject));
                        this.splitList.Remove(splitGroup);

                        //GameMetricLogger.Increment(GameMetricOptions.Splits);
                    }
                    else
                    {
                        splitGroup.Update();
                        this.splitList[i] = splitGroup;
                    }
                }
            }
            if (this.mergeList.Count > 0)
            {
                for (int i = this.mergeList.Count - 1; i >= 0; i--)
                {
                    Merge mergeGroup = this.mergeList[i];
                    if (mergeGroup.elapsedTime > 1f)
                    {
                        if (mergeGroup.merge != null)
                        {
                            NewGameUnit unit = mergeGroup.merge.GetComponent <NewGameUnit>();
                            if (unit != null)
                            {
                                NewChanges changes = unit.CurrentProperty();
                                changes.damage = unit.properties.maxHealth;
                                unit.NewProperty(changes);
                            }
                            NewUnitStruct temp = new NewUnitStruct();
                            temp.unit = unit.gameObject;
                            this.unitList.Remove(temp);
                            //CmdDestroy(temp.unit);
                        }
                        this.mergeList.RemoveAt(i);

                        //GameMetricLogger.Increment(GameMetricOptions.Merges);
                    }
                    else
                    {
                        mergeGroup.Update();
                        this.mergeList[i] = mergeGroup;
                    }
                }
            }
        }
コード例 #25
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
        private void ManageLists()
        {
            if (this.splitList.Count > 0)
            {
                for (int i = this.splitList.Count - 1; i >= 0; i--)
                {
                    Split splitGroup = this.splitList[i];
                    if (splitGroup.owner == null || splitGroup.split == null)
                    {
                        this.splitList.Remove(splitGroup);
                    }
                    if (splitGroup.elapsedTime > 1f)
                    {
                        NewGameUnit unit = splitGroup.owner.GetComponent <NewGameUnit>();
                        this.changes             = unit.CurrentProperty();
                        this.changes.isSelected  = false;
                        this.changes.isSplitting = false;
                        CmdUpdateUnitProperty(splitGroup.owner.gameObject, this.changes);
                        unit = splitGroup.split.GetComponent <NewGameUnit>();
                        CmdUpdateUnitProperty(splitGroup.split.gameObject, this.changes);
                        this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject));
                        this.splitList.Remove(splitGroup);

                        GameMetricLogger.Increment(GameMetricOptions.Splits);
                    }
                    else
                    {
                        splitGroup.Update();
                        this.splitList[i] = splitGroup;
                    }
                }
            }
            if (this.mergeList.Count > 0)
            {
                for (int i = this.mergeList.Count - 1; i >= 0; i--)
                {
                    Merge mergeGroup = this.mergeList[i];
                    if (mergeGroup.elapsedTime > 1f)
                    {
                        if (mergeGroup.owner != null)
                        {
                            NewGameUnit unit = mergeGroup.owner.gameObject.GetComponent <NewGameUnit>();
                            this.changes            = unit.CurrentProperty();
                            this.changes.isMerging  = false;
                            this.changes.isSelected = false;
                            //changes.newLevel = unit.properties.level + 1;
                            CmdUpdateUnitProperty(mergeGroup.owner.gameObject, this.changes);
                        }
                        if (mergeGroup.merge != null)
                        {
                            NewUnitStruct temp = new NewUnitStruct();
                            temp.unit = mergeGroup.merge.gameObject;
                            this.unitList.Remove(temp);
                            CmdDestroy(temp.unit);
                        }
                        this.mergeList.RemoveAt(i);

                        GameMetricLogger.Increment(GameMetricOptions.Merges);
                    }
                    else
                    {
                        mergeGroup.Update();
                        this.mergeList[i] = mergeGroup;
                    }
                }
            }
            this.isUnitListEmpty = this.unitList.Count <= 0;
            if (!this.isUnitListEmpty)
            {
                for (int i = this.unitList.Count - 1; i >= 0; i--)
                {
                    if (this.unitList[i].unit == null)
                    {
                        this.unitList.RemoveAt(i);
                        continue;
                    }
                    NetworkIdentity id = this.unitList[i].unit.GetComponent <NetworkIdentity>();
                    if (!id.hasAuthority)
                    {
                        CmdRemoveUnitList(this.unitList[i].unit);
                    }
                }
            }
            else
            {
                CmdShowReport();
            }
        }
コード例 #26
0
ファイル: NewSpawner.cs プロジェクト: cainiao1989/Multiplier
 private void SelectObjectsInRect()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         GameObject    obj  = temp.unit.gameObject;
         if (obj == null)
         {
             this.unitList.Remove(temp);
             continue;
         }
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         Vector3     projectedPosition = Camera.main.WorldToScreenPoint(obj.transform.position);
         projectedPosition.y = Screen.height - projectedPosition.y;
         if (unit != null && unit.hasAuthority)
         {
             if (this.isBoxSelecting)
             {
                 if (this.selectionBox.Contains(projectedPosition))
                 {
                     if (this.selectedList.Contains(temp))
                     {
                         this.changes            = unit.CurrentProperty();
                         this.changes.isSelected = false;
                         CmdUpdateUnitProperty(unit.gameObject, this.changes);
                         this.selectedList.Remove(temp);
                     }
                     else
                     {
                         this.changes       = unit.CurrentProperty();
                         changes.isSelected = true;
                         CmdUpdateUnitProperty(unit.gameObject, this.changes);
                         this.selectedList.Add(temp);
                     }
                 }
             }
             else
             {
                 if (unit.properties.isSelected)
                 {
                     if (!this.selectedList.Contains(temp))
                     {
                         this.selectedList.Add(temp);
                     }
                 }
                 else
                 {
                     if (!this.selectionBox.Contains(projectedPosition))
                     {
                         if (this.selectedList.Contains(temp))
                         {
                             this.changes            = unit.CurrentProperty();
                             this.changes.isSelected = false;
                             CmdUpdateUnitProperty(unit.gameObject, this.changes);
                             this.selectedList.Remove(temp);
                         }
                     }
                     else
                     {
                         if (!this.selectedList.Contains(temp))
                         {
                             this.changes = unit.CurrentProperty();
                             ;
                             changes.isSelected = true;
                             CmdUpdateUnitProperty(unit.gameObject, this.changes);
                             this.selectedList.Add(temp);
                         }
                     }
                 }
             }
         }
     }
 }