private void OnTriggerEnter(Collider other)
        {
            PrefabIdentifier componentInParent = other.GetComponentInParent <PrefabIdentifier>();

            if (componentInParent)
            {
                IHoleStructure holeStructure = (IHoleStructure)componentInParent.GetComponent(typeof(IHoleStructure));
                if (holeStructure != null && !this._targets.Contains(holeStructure))
                {
                    Hole item;
                    if (holeStructure is FloorArchitect)
                    {
                        FloorArchitect floorArchitect = UnityEngine.Object.Instantiate <FloorArchitect>(this._previewFloor);
                        (holeStructure as FloorArchitect).OnBuilt(floorArchitect.gameObject);
                        floorArchitect._wasBuilt = false;
                        this._previews.Add(floorArchitect);
                        item = floorArchitect.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize);
                    }
                    else
                    {
                        if (!(holeStructure is RoofArchitect))
                        {
                            Debug.LogError("Trying to cut IHS '" + componentInParent.name + "' which isn't roof or floor. Please report this to guillaume.");
                            return;
                        }
                        RoofArchitect roofArchitect = UnityEngine.Object.Instantiate <RoofArchitect>(this._previewRoof);
                        (holeStructure as RoofArchitect).OnBuilt(roofArchitect.gameObject);
                        roofArchitect._wasBuilt = false;
                        this._previews.Add(roofArchitect);
                        item = roofArchitect.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize);
                    }
                    this._targets.Add(holeStructure);
                    this._holes.Add(item);
                    base.enabled = true;
                    this.CheckCanPlace();
                }
            }
        }
		private bool TryAddTarget(PrefabIdentifier pi, Collider c)
		{
			if (pi)
			{
				IHoleStructure holeStructure = (IHoleStructure)pi.GetComponent(typeof(IHoleStructure));
				if (holeStructure != null)
				{
					if (!this._targets.Contains(holeStructure) && holeStructure.HoleCount < 20)
					{
						Hole item;
						if (holeStructure is FloorArchitect)
						{
							if (!this._previewFloor || !(holeStructure as FloorArchitect).WasBuilt)
							{
								return false;
							}
							FloorArchitect floorArchitect = holeStructure as FloorArchitect;
							FloorArchitect floorArchitect2 = UnityEngine.Object.Instantiate<FloorArchitect>(this._previewFloor, floorArchitect.transform.position, floorArchitect.transform.rotation);
							floorArchitect.OnBuilt(floorArchitect2.gameObject);
							floorArchitect2._wasBuilt = false;
							this._previews.Add(floorArchitect2);
							item = floorArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize);
						}
						else if (holeStructure is RoofArchitect)
						{
							if (!this._previewRoof || !(holeStructure as RoofArchitect).WasBuilt)
							{
								return false;
							}
							RoofArchitect roofArchitect = holeStructure as RoofArchitect;
							RoofArchitect roofArchitect2 = UnityEngine.Object.Instantiate<RoofArchitect>(this._previewRoof, roofArchitect.transform.position, roofArchitect.transform.rotation);
							roofArchitect.OnBuilt(roofArchitect2.gameObject);
							roofArchitect2._wasBuilt = false;
							this._previews.Add(roofArchitect2);
							item = roofArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize);
						}
						else
						{
							if (holeStructure is CraneArchitect)
							{
								return false;
							}
							if (!(holeStructure is RaftArchitect) || !(holeStructure as RaftArchitect).WasBuilt)
							{
								UnityEngine.Debug.LogError("Trying to cut IHS '" + pi.name + "' which isn't roof, floor or raft. Please report this to guillaume.");
								return false;
							}
							if (!this._previewRaft || !(base.transform.root != pi.transform.root))
							{
								return false;
							}
							RaftArchitect raftArchitect = holeStructure as RaftArchitect;
							RaftArchitect raftArchitect2 = UnityEngine.Object.Instantiate<RaftArchitect>(this._previewRaft, raftArchitect.transform.position, raftArchitect.transform.rotation);
							raftArchitect.OnBuilt(raftArchitect2.gameObject);
							this._previews.Add(raftArchitect2);
							item = raftArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize);
						}
						this._targets.Add(holeStructure);
						this._holes.Add(item);
						this.CheckCanPlace();
						return true;
					}
				}
				else
				{
					BuildingBlueprint blueprintByPrefabId = Prefabs.Instance.Constructions.GetBlueprintByPrefabId(pi.ClassId);
					if (blueprintByPrefabId != null && !blueprintByPrefabId._preventHoleCutting)
					{
						FloorHoleArchitect.DestroyTarget destroyTarget;
						if (!this._destroyTargets.TryGetValue(pi.gameObject, out destroyTarget))
						{
							destroyTarget = new FloorHoleArchitect.DestroyTarget();
							destroyTarget._go = pi.gameObject;
							destroyTarget._bh = pi.GetComponent<BuildingHealth>();
							ICoopStructure component = pi.GetComponent<ICoopStructure>();
							if (component != null)
							{
								IProceduralStructure component2 = pi.GetComponent<IProceduralStructure>();
								if (component2 == null)
								{
									return false;
								}
								destroyTarget._ghost = component2.SpawnStructure().gameObject;
							}
							else
							{
								destroyTarget._ghost = UnityEngine.Object.Instantiate<GameObject>(blueprintByPrefabId._ghostPrefab, pi.transform.position, pi.transform.rotation);
							}
							destroyTarget._ghost.transform.parent = pi.transform;
							int layer = LayerMask.NameToLayer("TransparentFX");
							Renderer component3 = destroyTarget._ghost.GetComponent<Renderer>();
							if (component3)
							{
								destroyTarget._ghost.layer = layer;
								component3.sharedMaterial = this._overlayMaterial;
							}
							else
							{
								Craft_Structure componentInChildren = destroyTarget._ghost.GetComponentInChildren<Craft_Structure>();
								if (componentInChildren && componentInChildren._requiredIngredients.Count > 0)
								{
									for (int i = 0; i < componentInChildren._requiredIngredients.Count; i++)
									{
										Craft_Structure.BuildIngredients buildIngredients = componentInChildren._requiredIngredients[i];
										buildIngredients.SetGhostMaterial(this._overlayMaterial);
									}
								}
								else
								{
									Renderer[] componentsInChildren = destroyTarget._ghost.GetComponentsInChildren<Renderer>();
									foreach (Renderer renderer in componentsInChildren)
									{
										renderer.gameObject.layer = layer;
										renderer.sharedMaterial = this._overlayMaterial;
									}
								}
							}
							Transform transform = destroyTarget._ghost.transform.Find("Trigger");
							if (transform)
							{
								UnityEngine.Object.Destroy(transform.gameObject);
							}
							LastBuiltLocation component4 = destroyTarget._ghost.GetComponent<LastBuiltLocation>();
							if (component4)
							{
								UnityEngine.Object.Destroy(component4.gameObject);
							}
							LastBuiltLocation component5 = destroyTarget._ghost.GetComponent<LastBuiltLocation>();
							if (component5)
							{
								UnityEngine.Object.Destroy(component5.gameObject);
							}
							UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<PrefabIdentifier>());
							UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<SingleAnchorStructure>());
							this._destroyTargets.Add(pi.gameObject, destroyTarget);
						}
						if (c && !destroyTarget._colliders.Contains(c))
						{
							destroyTarget._colliders.Add(c);
						}
						this.CheckCanPlace();
						return true;
					}
				}
			}
			return false;
		}
Exemple #3
0
        private void SpawnGizmos()
        {
            List <Vector3> multiPointsPositions = this._structure.GetMultiPointsPositions(true);

            if (multiPointsPositions.Count > 0)
            {
                Transform item = PoolManager.Pools["misc"].Spawn(this._pointGizmo, multiPointsPositions[0] + this._offset, Quaternion.identity);
                this._gizmos.Add(item);
                Transform transform;
                for (int i = 1; i < multiPointsPositions.Count; i++)
                {
                    item                 = PoolManager.Pools["misc"].Spawn(this._pointGizmo, multiPointsPositions[i] + this._offset, Quaternion.identity);
                    transform            = PoolManager.Pools["misc"].Spawn(this._lineGizmo, multiPointsPositions[i] + this._offset, Quaternion.LookRotation(multiPointsPositions[i - 1] - multiPointsPositions[i]));
                    transform.localScale = new Vector3(1f, 1f, Vector3.Distance(multiPointsPositions[i], multiPointsPositions[i - 1]));
                    this._gizmos.Add(item);
                    this._gizmos.Add(transform);
                }
                Vector3 vector = multiPointsPositions[multiPointsPositions.Count - 1];
                Vector3 vector2;
                if (this._structure is FloorArchitect)
                {
                    vector2 = (this._structure as FloorArchitect).GetCurrentEdgePoint();
                }
                else if (this._structure is FoundationArchitect)
                {
                    vector2 = (this._structure as FoundationArchitect).GetCurrentEdgePoint();
                }
                else if (this._structure is RoofArchitect)
                {
                    RoofArchitect roofArchitect = this._structure as RoofArchitect;
                    if (roofArchitect.LockMode == RoofArchitect.LockModes.Height)
                    {
                        return;
                    }
                    vector2 = roofArchitect.GetCurrentEdgePoint();
                }
                else
                {
                    vector2   = (this._structure as MonoBehaviour).transform.position;
                    vector2.y = vector.y;
                }
                item                 = PoolManager.Pools["misc"].Spawn(this._pointGizmo, vector2 + this._offset, Quaternion.identity);
                transform            = PoolManager.Pools["misc"].Spawn(this._lineGizmo, vector2 + this._offset, Quaternion.LookRotation(vector - vector2));
                transform.localScale = new Vector3(1f, 1f, Vector3.Distance(vector2, vector));
                this._gizmos.Add(item);
                this._gizmos.Add(transform);
            }
            else
            {
                Vector3 vector2;
                if (this._structure is FloorArchitect)
                {
                    vector2 = (this._structure as FloorArchitect).GetCurrentEdgePoint();
                }
                else if (this._structure is RoofArchitect)
                {
                    vector2 = (this._structure as RoofArchitect).GetCurrentEdgePoint();
                }
                else
                {
                    vector2   = (this._structure as MonoBehaviour).transform.position;
                    vector2.y = this._structure.GetLevel();
                }
                Transform item = PoolManager.Pools["misc"].Spawn(this._pointGizmo, vector2 + this._offset, Quaternion.identity);
                this._gizmos.Add(item);
            }
        }