Example #1
0
    void SpawnBlock(PartToken token, Vector3 pos, Quaternion rot, int owner)
    {
        if (GlobalReferences.FrozenParts.ContainsKey(token.ID))
        {
            return;
        }

        GameObject newBlock = GlobalReferences.PartSpawner.SpawnGhostPart(token.TemplateID);

        newBlock.transform.position = pos;
        newBlock.transform.rotation = rot;

        Part newPart = newBlock.GetComponent <Part>();

        newPart.PartOwner = owner;

        newPart.FreezePart(token.ID);

        if (!GlobalReferences.PartIDLedger.ContainsKey(token.ID))
        {
            GlobalReferences.PartIDLedger.Add(token.ID, GlobalReferences.GetNextID());
        }

        if (token.Disabled)
        {
            newPart.Disable();
        }
    }
Example #2
0
    public override void OnEvent(BlockDestroy evnt)
    {
        if (entity.IsOwner)
        {
            GlobalReferences.AffectedParts.Remove(gameObject);
            GlobalReferences.FreeParts.Remove(gameObject);

            Part p = GetComponent <Part>();
            if (PlacementReferences.InfiniteParts && p.Respawn)
            {
                GameObject go = GlobalReferences.PartSpawner.SpawnPart(p.TemplateID);
                go.GetComponent <Part>().Respawn = true;

                if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
                {
                    GlobalReferences.AffectPart(go);
                    GlobalReferences.FreeParts.Remove(go);
                }
            }
            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
            }

            BoltNetwork.Destroy(gameObject);
        }
    }
Example #3
0
    public override void ActivateItem()
    {
        active = !active;

        if (!BoltNetwork.IsRunning || ControllerReferences.IndependantMP)
        {
            if (active)
            {
                GlobalReferences.TypeFilter.Add(templateID, GlobalReferences.PartProbs[templateID]);
                Highlight();
            }
            else
            {
                GlobalReferences.TypeFilter.Remove(templateID);
                Lowlight();
            }

            GlobalReferences.ClearAffectedList();
            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
            }
        }
        else
        {
            ChangePartFilter evnt = ChangePartFilter.Create();
            evnt.State = active;
            evnt.ID    = templateID;
            evnt.Send();
        }
    }
Example #4
0
 //methods
 #region
 public void ChangeTool(ToolsetControls.InputX input)
 {
     if (input == ToolsetControls.InputX.Enter)
     {
         return;
     }
     else if (input == ToolsetControls.InputX.Left)
     {
         if (affectedParts > 0)
         {
             --affectedParts;
             if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
             {
                 GlobalReferences.ChangeAffectedNumber(affectedParts);
             }
         }
         textMesh.text = affectedParts.ToString();
     }
     else if (input == ToolsetControls.InputX.Right)
     {
         if (affectedParts < 999 && affectedParts <= GlobalReferences.FreeParts.Count + GlobalReferences.AffectedParts.Count)
         {
             ++affectedParts;
             if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
             {
                 GlobalReferences.ChangeAffectedNumber(affectedParts);
             }
         }
         textMesh.text = affectedParts.ToString();
     }
 }
Example #5
0
        /// <summary>
        /// Sets up exported file dummy
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <returns>Exported file dummy</returns>
        public ExportedFile SetupExportedFile(string fileName = null)
        {
            if ((!_context.Hierarchical) && fileName == _context.TargetFile)
            {
                fileName = null;
            }
            IEnumerable <Type> types = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (!_typesToFilesMap.ContainsKey(fileName))
                {
                    var allFiles = string.Join(", ", _typesToFilesMap.Keys);
                    throw new Exception("Current configuration does not contain file " + fileName + ", only " + allFiles);
                }

                types = _typesToFilesMap[fileName];
            }

            ExportedFile ef = new ExportedFile
            {
                References           = GlobalReferences.Duplicate(),
                FileName             = fileName,
                AllTypesIsSingleFile = !_context.Hierarchical,
                TypesToExport        = _context.Hierarchical ? new HashSet <Type>(types) : _allTypesHash
            };

            ef.TypeResolver = new TypeResolver(_context, ef, ReferenceInspector);
            _context.Project.AddReferencesFromTypes(ef, _context.Global.UseModules);
            return(ef);
        }
    //public GameObject splashPrefab;

    // Use this for initialization
    void Start()
    {
        globals      = GameObject.Find("GlobalReferences").GetComponent <GlobalReferences>();
        waveMaterial = gameObject.GetComponent <Renderer>().sharedMaterial;

        collisionEvents = new ParticleCollisionEvent[16];
    }
Example #7
0
    public static void AfterSimulation(TextMeshPro tm)
    {
        ++handlerCallBack;
        if (handlerCallBack == handlers.Count)
        {
            SaveLoadTool.SaveGame("Sim_");

            List <GameObject> tempGos = new List <GameObject>();
            foreach (GameObject go in GlobalReferences.FrozenParts.Values)
            {
                tempGos.Add(go);
            }

            GlobalReferences.FrozenParts.Clear();

            ChangeColliders(true);

            for (int i = tempGos.Count - 1; i >= 0; --i)
            {
                Destroy(tempGos[i]);
            }

            AssemblyIO.Load(tempPath);
            GlobalReferences.RebuildIndices();

            tm.text      = "Run\nSimulation";
            tm.faceColor = GlobalReferences.UnaffectedColor;

            simulationInProgress = false;

            handlers.Clear();
            handlerCallBack = 0;
        }
    }
Example #8
0
 void deactivateAllPlacementTools()
 {
     GlobalReferences.ClearAffectedList();
     PlacementBehaviour.CarryGo[PlacementBehaviour.TempID].SetActive(false);
     PlacementBehaviour.ReleasePart();
     PlacementBehaviour.Aiming = false;
     PlacementBehaviour.DisableSphere.SetActive(false);
 }
Example #9
0
    IEnumerator Activate()
    {
        for (int i = 0; i < GlobalReferences.Parts.Count; ++i)
        {
            GlobalReferences.Parts[i].SetActive(true);
            yield return(new WaitForSeconds(0.001f));
        }

        GlobalReferences.ChangeAffectedNumber(NumberOfPartsTool.AffectedParts);
    }
Example #10
0
    public void LocalDelete()
    {
        GlobalReferences.DeletePart(id);

        if (!PlacementReferences.InfiniteParts && Respawn)
        {
            GameObject go = PartsHolder.Holder.SpawnPart(GetComponent <Part>().TemplateID);
            go.GetComponent <Part>().Respawn = true;
        }
    }
Example #11
0
    public static void SpawnBlockParent(PartTokenParent token, Vector3 pos, Quaternion rot, int owner)
    {
        if (GlobalReferences.FrozenParts.ContainsKey(token.ID))
        {
            Debug.LogError("Frozen Parts already containts Key " + token.ID);
            return;
        }

        GameObject newBlock = GlobalReferences.PartSpawner.SpawnGhostPart(token.TemplateID, pos, rot);

        Destroy(newBlock.GetComponent <ConstantForce>());
        Destroy(newBlock.GetComponent <Rigidbody>());

        Part newPart = newBlock.GetComponent <Part>();

        newPart.SetInactive(token.Con);
        newPart.Parent    = token.Parent;
        newPart.ParentCon = token.ParentCon;
        newPart.PartOwner = owner;

        if (token.Parent != -1 && GlobalReferences.FrozenParts.ContainsKey(token.Parent))
        {
            Part parentPart = GlobalReferences.FrozenParts[token.Parent].GetComponent <Part>();
            parentPart.Children.Add(token.ID);
            parentPart.ChildCons.Add(token.Con);
            try
            {
                parentPart.SetInactive(parentPart.Connections[token.ParentCon]);
            }
            catch
            {
                Debug.LogError("parentPart: " + parentPart.ID + " doesnt contain connection: " + token.ParentCon);
            }
        }
        else if (token.Parent != -1)
        {
            var wait = newBlock.AddComponent <NetworkPartWaitForParent>();
            wait.Initialize(token.Parent, token.ID, token.Con, token.ParentCon);
        }

        newPart.FreezePart(token.ID);

        if (!GlobalReferences.PartIDLedger.ContainsKey(token.ID))
        {
            GlobalReferences.PartIDLedger.Add(token.ID, GlobalReferences.GetNextID());
        }

        if (token.Disabled)
        {
            newPart.Disable();
        }

        //Debug.Log("#43 Block Transform Done: " + token.ID + ", Position = " + newBlock.transform.position.ToString("F2") + ", Rotation = " + newBlock.transform.rotation.eulerAngles.ToString("F2"));
    }
Example #12
0
 public override void RightPressed()
 {
     if (PlacementReferences.AffectedParts < GlobalReferences.FreeParts.Count + GlobalReferences.AffectedParts.Count)
     {
         ++PlacementReferences.AffectedParts;
         if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
         {
             GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
         }
     }
     affectedPartsCounter.text = PlacementReferences.AffectedParts.ToString();
 }
Example #13
0
 public override void LeftPressed()
 {
     if (PlacementReferences.AffectedParts > 0)
     {
         --PlacementReferences.AffectedParts;
         if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
         {
             GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
         }
     }
     affectedPartsCounter.text = PlacementReferences.AffectedParts.ToString();
 }
 void Awake()
 {
     if (!reference)
     {
         reference = this;
     }
     else if (reference != this)
     {
         Debug.LogError("There are two GlobalReferences components in the scene. One has been deleted.");
         Destroy(gameObject);
     }
 }
Example #15
0
    public void ChangeTool(ToolsetControls.InputX input)
    {
        if (input == ToolsetControls.InputX.Enter)
        {
            if (activityFlags[offset])
            {
                activityFlags[offset] = false;
                GlobalReferences.TypeFilter.Remove(partNames[offset]);

                GlobalReferences.ClearAffectedList();
                if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
                {
                    GlobalReferences.ChangeAffectedNumber(NumberOfPartsTool.AffectedParts);
                }
            }
            else
            {
                activityFlags[offset] = true;
                GlobalReferences.TypeFilter.Add(partNames[offset]);

                GlobalReferences.ClearAffectedList();
                if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
                {
                    GlobalReferences.ChangeAffectedNumber(NumberOfPartsTool.AffectedParts);
                }
            }

            ChangeColor();
        }
        else if (input == ToolsetControls.InputX.Left)
        {
            if (offset > 0)
            {
                --offset;
                foreach (GameObject go in templates)
                {
                    go.transform.localPosition = go.transform.localPosition - translateOffset;
                }
            }
        }
        else if (input == ToolsetControls.InputX.Right)
        {
            if (offset < activityFlags.Count - 1)
            {
                ++offset;
                foreach (GameObject go in templates)
                {
                    go.transform.localPosition = go.transform.localPosition + translateOffset;
                }
            }
        }
    }
 public GlobalReferences(IProvideVBScriptCompatFunctionalityToIndividualRequests compatLayer, EnvironmentReferences env)
 {
     if (compatLayer == null)
     {
         throw new ArgumentNullException("compatLayer");
     }
     if (env == null)
     {
         throw new ArgumentNullException("env");
     }
     _      = compatLayer;
     _env   = env;
     _outer = this;
     i      = null;
 }
        public void Go(EnvironmentReferences env)
        {
            if (env == null)
            {
                throw new ArgumentNullException("env");
            }

            var _env   = env;
            var _outer = new GlobalReferences(_, _env);

            // Test
            for (_outer.i = (Int16)1; _.StrictLTE(_outer.i, 10); _outer.i = _.ADD(_outer.i, (Int16)1))
            {
                _.CALL(this, _env.wscript, "Echo", _.ARGS.Val(_.CONCAT("Item", _outer.i)));
            }
        }
Example #18
0
    public override void OnEvent(BlockFreeze evnt)
    {
        Destroy(gameObject.GetComponent <ConstantForce>());
        Part p = gameObject.GetComponent <Part>();

        gameObject.transform.position = evnt.BlockPosition;
        gameObject.transform.rotation = evnt.BlockRotation;

        p.FreezePart(evnt.ID);
        p.Parent    = evnt.ParentID;
        p.ParentCon = evnt.ParentCon;

        Part parentPart = GlobalReferences.FrozenParts[evnt.ParentID].GetComponent <Part>();

        ConnectionVoxelContainer.RemoveConnection(parentPart.Connections[evnt.ParentCon]);
        ConnectionVoxelContainer.RemoveConnection(gameObject.GetComponent <Part>().Connections[evnt.ConnectionID]);

        parentPart.ChildCons.Add(evnt.ConnectionID);
        parentPart.SetInactive(parentPart.Connections[evnt.ParentCon]);
        p.SetInactive(p.Connections[evnt.ConnectionID]);

        parentPart.Children.Add((int)p.ID);

        gameObject.transform.position = evnt.BlockPosition;
        gameObject.transform.rotation = evnt.BlockRotation;

        if (PlacementReferences.InfiniteParts && entity.IsOwner && p.Respawn)
        {
            GameObject go = GlobalReferences.PartSpawner.SpawnPart(p.TemplateID);
            go.GetComponent <Part>().Respawn = true;

            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.AffectPart(go);
                GlobalReferences.FreeParts.Remove(go);
            }
        }
        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo && entity.IsOwner)
        {
            GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
        }

        if (entity.IsOwner)
        {
            //entity.Freeze(true);
        }
    }
Example #19
0
    public void Engage()
    {
        switch (GlobalReferences.PlacementType)
        {
        case PlacementTypeTool.PlaceChoreo.Place:
        {
            FreezeObject();
            break;
        }

        case PlacementTypeTool.PlaceChoreo.Choreo:
        {
            GlobalReferences.DriftApartFac = 1;
            break;
        }

        case PlacementTypeTool.PlaceChoreo.PickNChose:
        {
            if (pickup != null)
            {
                PickupPart();
            }
            else if (pickupCarry != null && pickup == null)
            {
                ReleasePart();
            }
            break;
        }

        case PlacementTypeTool.PlaceChoreo.Delete:
        {
            if (toDelete != null)
            {
                GlobalReferences.DeletePart((int)toDelete.GetComponent <Part>().ID);
            }
            break;
        }

        case PlacementTypeTool.PlaceChoreo.DisableScanning:
        {
            trigger.Enable    = true;
            trigger.Triggered = true;
            break;
        }
        }
    }
Example #20
0
    private void RealizeConnection()
    {
        if (lastDistAngle < connectionThreshold && ConnectionVoxelContainer.RevealConnections(bestOnPart).Contains(closestConnection))
        {
            Vector3    pos = gameObject.transform.position;
            Quaternion rot = gameObject.transform.rotation;

            AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject);

            if (!CollisionDetection())
            {
                Part p = gameObject.GetComponent <Part>();
                p.FreezePart();
                p.Parent    = closestConnection.ParentPart.ID;
                p.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);

                ConnectionVoxelContainer.RemoveConnection(closestConnection);
                ConnectionVoxelContainer.RemoveConnection(bestOnPart);

                bestOnPart.ParentPart.SetInactive(bestOnPart);
                closestConnection.ParentPart.SetInactive(closestConnection);
                closestConnection.ParentPart.ChildCons.Add(bestOnPart.ParentPart.Connections.IndexOf(bestOnPart));

                closestConnection.ParentPart.Children.Add((int)p.ID);

                GameObject _g = PartsHolder.SpawnPart(p.TemplateID);
                _g.SetActive(true);
                if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
                {
                    GlobalReferences.AffectPart(_g);
                    GlobalReferences.FreeParts.Remove(_g);
                }

                ConnectionScanningHandler handler = gameObject.GetComponent <ConnectionScanningHandler>();
                if (handler != null)
                {
                    handler.TerminateConnection();
                }
            }
            else
            {
                gameObject.transform.position = pos;
                gameObject.transform.rotation = rot;
            }
        }
    }
Example #21
0
    public override void OnEvent(ChangePartFilter evnt)
    {
        if (evnt.State)
        {
            GlobalReferences.TypeFilter.Add(evnt.ID, GlobalReferences.PartProbs[evnt.ID]);
        }
        else
        {
            GlobalReferences.TypeFilter.Remove(evnt.ID);
        }

        GlobalReferences.ClearAffectedList();
        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
        {
            GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
        }

        partFilterTIs[evnt.ID].ChangeState(evnt.State);
    }
Example #22
0
        private static jvalue[] CreateVibrationEffect(long durationMs, int amplitude)
        {
            if (!IsAndroid())
            {
                return(null);
            }

            if (!VibrateEffectArgsCache.TryGetValue((durationMs, amplitude), out var args))
            {
                var effect = VibrationEffectClass?.CallStatic <AndroidJavaObject>("createOneShot", durationMs, amplitude);

                if (effect != null)
                {
                    GlobalReferences.Add(effect);
                }

                args = new[] { new jvalue {
                                   l = effect?.GetRawObject() ?? IntPtr.Zero
                               } };
                VibrateEffectArgsCache[(durationMs, amplitude)] = args;
Example #23
0
    static void Export(TIExportAR exportItem)
    {
        if (GlobalReferences.FrozenParts.Count > 1)
        {
            int k = 0;

            foreach (int kk in GlobalReferences.FrozenParts.Keys)
            {
                if (kk > k)
                {
                    k = kk;
                }
            }

            GlobalReferences.DeletePart(k);

            ParentAndSimulate(exportItem, true);

            --expCount;
        }
        else
        {
            exportItem.ResetTool();

            simulationInProgress = false;

            int k = 0;
            foreach (int i in GlobalReferences.FrozenParts.Keys)
            {
                k = i;
            }

            GlobalReferences.DeletePart(k);

            expCount = 0;
            AssemblyIO.Load(expTempPath);

            ControllerReferences.ControllerTarget.SetActive(true);
        }
    }
Example #24
0
    void ToolChangeCaseHandler()
    {
        switch (active)
        {
        case PlaceChoreo.Place:
        {
            deactivateAllPlacementTools();
            PlacementBehaviour.CarryGo[PlacementBehaviour.TempID].SetActive(true);
            break;
        }

        case PlaceChoreo.Choreo:
        {
            deactivateAllPlacementTools();
            GlobalReferences.ChangeAffectedNumber(NumberOfPartsTool.AffectedParts);
            break;
        }

        case PlaceChoreo.PickNChose:
        {
            deactivateAllPlacementTools();
            PlacementBehaviour.Aiming = true;
            break;
        }

        case PlaceChoreo.Delete:
        {
            deactivateAllPlacementTools();
            PlacementBehaviour.Aiming = true;
            break;
        }

        case PlaceChoreo.DisableScanning:
        {
            deactivateAllPlacementTools();
            PlacementBehaviour.DisableSphere.SetActive(true);
            break;
        }
        }
    }
Example #25
0
    public static void NewGame()
    {
        if (BoltNetwork.IsRunning)
        {
            var newGame = NewGameEvent.Create();
            newGame.Send();
            return;
        }

        List <GameObject> tempGos = new List <GameObject>();

        tempGos.AddRange(GlobalReferences.FreeParts);
        tempGos.AddRange(GlobalReferences.AffectedParts);

        foreach (GameObject go in GlobalReferences.FrozenParts.Values)
        {
            tempGos.Add(go);
        }

        for (int i = tempGos.Count - 1; i >= 0; --i)
        {
            if (tempGos[i].GetComponent <Part>().ID != -1)
            {
                GlobalReferences.DeletePart((int)tempGos[i].GetComponent <Part>().ID);
            }
            else
            {
                MonoBehaviour.Destroy(tempGos[i]);
            }
        }

        GlobalReferences.FreeParts.Clear();
        GlobalReferences.FrozenParts.Clear();
        GlobalReferences.AffectedParts.Clear();
        GlobalReferences.NumOfParts = 0;
        GlobalReferences.Parts.Clear();

        GlobalReferences.PartSpawner.SpawnMultiple(PartsHolder.NumParts);
    }
Example #26
0
    void FreezeSinglePlayer()
    {
        Part p = gameObject.GetComponent <Part>();

        p.FreezePart();

        p.Parent    = closestConnection.ParentPart.ID;
        p.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);

        p.ConToParent = bestOnPart.ParentPart.Connections.IndexOf(bestOnPart);

        ConnectionVoxelContainer.RemoveConnection(closestConnection);
        ConnectionVoxelContainer.RemoveConnection(bestOnPart);

        closestConnection.ParentPart.ChildCons.Add(bestOnPart.ParentPart.Connections.IndexOf(bestOnPart));
        closestConnection.ParentPart.Children.Add((int)p.ID);


        bestOnPart.ParentPart.SetInactive(bestOnPart);
        closestConnection.ParentPart.SetInactive(closestConnection);

        if (PlacementReferences.InfiniteParts && p.Respawn)
        {
            GameObject go = GlobalReferences.PartSpawner.SpawnPart(p.TemplateID);
            go.GetComponent <Part>().Respawn = true;

            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.AffectPart(go);
                GlobalReferences.FreeParts.Remove(go);
            }
        }
        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
        {
            GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
        }
    }
Example #27
0
 public static void LoadGame(string path)
 {
     Debug.Log(SavePath + "/" + path);
     AssemblyIO.Load(SavePath + "/" + path);
     GlobalReferences.RebuildIndices();
 }
Example #28
0
    //public GameObject splashPrefab;

	// Use this for initialization
	void Start ()
    {
        globals = GameObject.Find("GlobalReferences").GetComponent<GlobalReferences>();
        waveMaterial = gameObject.GetComponent<Renderer>().sharedMaterial;
	}
Example #29
0
    //public GameObject splashPrefab;

    // Use this for initialization
    void Start()
    {
        globals      = GameObject.Find("GlobalReferences").GetComponent <GlobalReferences>();
        waveMaterial = gameObject.GetComponent <Renderer>().sharedMaterial;
    }
Example #30
0
    //Loading
    public static void Load(string path)
    {
        JsonAssembly assembly;

        string jsonSr;

        int numParts = 0;

        Matrix4x4 transM = new Matrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 0, 1));

        using (FileStream stream = new FileStream(path, FileMode.Open))
        {
            using (StreamReader sr = new StreamReader(stream))
            {
                jsonSr = sr.ReadToEnd();
            }
        }
        assembly = JsonConvert.DeserializeObject <JsonAssembly>(jsonSr);

        foreach (KeyValuePair <string, JsonPart> dicEntry in assembly.parts)
        {
            int id = int.Parse(dicEntry.Key) + GlobalReferences.NumOfParts;

            JsonPart part       = dicEntry.Value;
            int      templateId = GlobalReferences.TemplateIDFromName(part.name);
            if (templateId == -1)
            {
                throw new System.Exception("Couldn't find Part from Name");
            }

            GameObject go = MonoBehaviour.Instantiate(GlobalReferences.TemplateParts[templateId]);
            go.name = part.name + "_" + (id + GlobalReferences.NumOfParts);
            go.SetActive(true);

            PartsHolder.ResetPart(go, GlobalReferences.TemplateParts[templateId], id + GlobalReferences.NumOfParts);

            Part p = go.GetComponent <Part>();

            foreach (int child in part.children)
            {
                p.Children.Add(child + GlobalReferences.NumOfParts);
            }

            if (part.parent != null)
            {
                p.Parent = part.parent + GlobalReferences.NumOfParts;
            }
            else
            {
                p.Parent = null;
            }

            p.ParentCon = part.parentCon;

            p.ChildCons = part.childCons;

            p.ActiveConnections = part.activeConnections;

            Matrix4x4 m = part.transform.GetMatrix();

            m = transM * m;

            go.transform.localScale = JsonTransform.MatrixToScale(m);
            go.transform.rotation   = JsonTransform.MatrixToRotation(m);
            go.transform.position   = JsonTransform.MatrixToPosition(m);



            /*
             * go.transform.localScale = JsonTransform.MatrixToScale(m);
             * go.transform.rotation = JsonTransform.MatrixToRotation(m);
             * go.transform.position = JsonTransform.MatrixToPosition(m);
             * go.transform.RotateAround(Vector3.zero, Vector3.right, -90);
             * GameObject _go = new GameObject();
             * go.transform.SetParent(_go.transform);
             * _go.transform.localScale = new Vector3(1, 1, -1);
             * go.transform.SetParent(null);
             * MonoBehaviour.Destroy(_go);
             */



            p.FreezePart(id);

            CollisionVoxelContainer.StoreGameObject(go);
            if (!GlobalReferences.Parts.Contains(go))
            {
                GlobalReferences.Parts.Add(go);
            }

            if (id >= numParts)
            {
                numParts = id + GlobalReferences.NumOfParts + 1;
            }
        }

        GlobalReferences.NumOfParts = numParts;
    }
Example #31
0
    public void FreezePart(int _id = -1)
    {
        if (!TestDeleteSpawn())
        {
            Destroy(gameObject);
            return;
        }

        placedMat = Resources.Load <Material>("Materials/" + MaterialHolder.MatSet + "/PlacedMaterial");
        gameObject.GetComponent <MeshRenderer>().material = placedMat;

        gameObject.layer = 9;

        if (GetComponent <ConstantForce>() != null)
        {
            Destroy(gameObject.GetComponent <ConstantForce>());
        }

        if (GetComponent <Rigidbody>() != null)
        {
            Destroy(gameObject.GetComponent <Rigidbody>());
        }

        if (GetComponent <PartBehaviour>() != null)
        {
            Destroy(gameObject.GetComponent <PartBehaviour>());
        }

        if (GetComponent <ConnectionScanning>() != null)
        {
            Destroy(gameObject.GetComponent <ConnectionScanning>());
        }

        if (GetComponent <KillTimer>() != null)
        {
            Destroy(GetComponent <KillTimer>());
        }

        gameObject.isStatic = true;

        foreach (int i in ActiveConnections)
        {
            ConnectionVoxelContainer.StoreConnection(connections[i]);
        }

        CollisionVoxelContainer.StoreGameObject(gameObject);


        if (GlobalReferences.AffectedParts.Contains(gameObject))
        {
            GlobalReferences.AffectedParts.Remove(gameObject);
        }

        if (GlobalReferences.FreeParts.Contains(gameObject))
        {
            GlobalReferences.FreeParts.Remove(gameObject);
        }

        if (_id == -1)
        {
            id = GlobalReferences.GetNextID();
        }
        else
        {
            id = _id;
        }

        GlobalReferences.FrozenParts.Add((int)ID, gameObject);
        gameObject.name = name + "_" + id;

        if (TICtrlZ.LastID != ID)
        {
            TICtrlZ.History.Push(new HistoryItem(ID));
        }

        //Debug.Log("#43 Block Transform Frozen: " + ID + ", Position = " + transform.position.ToString("F2") + ", Rotation = " + transform.rotation.eulerAngles.ToString("F2"));
    }