private void Spawn(ref GameObject obj, Tool.ShipPart part) { switch (part.Param.Type) { case Tool.TypeCube.Body: obj = Builder.Instance.Build(Builder.FactoryType.Ship, (int)BuilderShip.Type.Body, Vector3.zero, Quaternion.identity, transform); break; case Tool.TypeCube.Cockpit: obj = Builder.Instance.Build(Builder.FactoryType.Ship, (int)BuilderShip.Type.Cockpit, Vector3.zero, Quaternion.identity, transform); break; case Tool.TypeCube.Gun: obj = Builder.Instance.Build(Builder.FactoryType.Ship, (int)BuilderShip.Type.Gun, Vector3.zero, Quaternion.identity, transform); break; case Tool.TypeCube.Power: obj = Builder.Instance.Build(Builder.FactoryType.Ship, (int)BuilderShip.Type.Power, Vector3.zero, Quaternion.identity, transform); break; default: Debug.LogError("Type of part ship doesn't support."); break; } }
public void Init(Tool.ShipPart part) { UnitPos posInit = part.Cubes[0]; //X = new Vector2(posInit.x, posInit.x); Y = new Vector2(posInit.y, posInit.y); Z = new Vector2(posInit.z, posInit.z); foreach (UnitPos pos in part.Cubes) { LinkPosList.Add(new LinkPos(pos, ParamAttribut != null ? ParamAttribut.Life : int.MaxValue)); // update min and max X.x = Mathf.Min(X.x, pos.x); X.y = Mathf.Max(X.y, pos.x); Y.x = Mathf.Min(Y.x, pos.y); Y.y = Mathf.Max(Y.y, pos.y); Z.x = Mathf.Min(Z.x, pos.z); Z.y = Mathf.Max(Z.y, pos.z); } // init component // size of cube float size = part.Param.SquareSize; CompMeshGenerator.ParamCubeSize = ScriptableObject.CreateInstance(typeof(Tool.SCROneValue)) as Tool.SCROneValue; CompMeshGenerator.ParamCubeSize.Value = size; CompMaterial.ParamMaterial = ScriptableObject.CreateInstance(typeof(Tool.SCRMaterial)) as Tool.SCRMaterial; CompMaterial.ParamMaterial.Material = part.Param.Material; }
private void CreatePart(int hashId) { // spawn entity ship part GameObject obj = null; ShipPart part = new ShipPart(ParamCube); Spawn(ref obj, part); EntShipPart entity = obj.GetComponent <EntShipPart>(); entity.Init(part); // force start on entity entity.Start(); ShipPartEntities.Add(hashId, entity); }