protected virtual void CallActions(string p_name, object p_value)
    {
        foreach (ShowObjectByParameterNameStruct v_struct in ObjectsToEnableOrDisable)
        {
            if (v_struct != null && v_struct.ObjectToApply != null)
            {
                if (v_struct.StateActionsList != null)
                {
                    foreach (ParameterNameStateAction v_stateAction in v_struct.StateActionsList)
                    {
                        if (v_stateAction != null)
                        {
                            if (v_stateAction.StateToMakeAction.Equals(p_name))
                            {
                                KiltUtils.SetContainerVisibility(v_struct.ObjectToApply, v_stateAction.Action, v_stateAction.DelayToCallAction, true);
                                break;
                            }
                        }
                    }
                }
            }
        }

        foreach (ParameterCallbackStruct v_struct in ParametersCallback)
        {
            if (v_struct != null && string.Equals(v_struct.ParameterName, p_name))
            {
                if (v_struct.OnParameterReceivedCallback != null)
                {
                    v_struct.OnParameterReceivedCallback.Invoke();
                }
            }
        }
    }
    public static T Deserialize <T>(string p_folder, string p_file, bool p_folderIsRelativePath = true, SerializationTypeEnum p_serializationType = SerializationTypeEnum.AutoDetect)
    {
        string v_resultPath          = KiltUtils.GetCompleteDataPath(p_folder, p_file, p_folderIsRelativePath);
        T      v_desserializedObject = Deserialize <T>(v_resultPath, p_serializationType);

        return(v_desserializedObject);
    }
 protected override void Refresh(bool p_force = true)
 {
     if (p_force || m_windowInformation.Ropes != null)
     {
         Rope2D.CleanUselessRopes();
         GameObject v_parentTransform = GameObject.Find("RopesContainer");
         if (v_parentTransform != null)
         {
             m_windowInformation.RopeParent = v_parentTransform.transform;
         }
         List <TackRope> v_tackList = new List <TackRope>(KiltUtils.FindAllResourcesComponentsAtFolder <TackRope>("Prefabs"));
         m_windowInformation.SelectedRopeIndex = 0;
         m_windowInformation.Ropes             = new List <Rope2D>();
         foreach (TackRope v_tackRope in v_tackList)
         {
             if (v_tackRope != null)
             {
                 m_windowInformation.Ropes.Add(v_tackRope);
             }
         }
         if (p_force && m_selectedObjects != null && m_windowInformation.PickSelectedObjects)
         {
             m_selectedObjects.Clear();
         }
         FillSelectedObjects();
     }
 }
 private void HideAllComponentsInInspector()
 {
     Component[] v_components = GetComponents <Component>();
     foreach (Component v_component in v_components)
     {
         if (v_component != null && v_component != this && v_component != this.transform)
         {
             //Dont Hide Special Properties
             if (v_component is BlockSpecialProperty)
             {
                 v_component.hideFlags &= ~HideFlags.HideInInspector;
                 v_component.hideFlags &= ~HideFlags.NotEditable;
             }
             else
             {
                 v_component.hideFlags |= HideFlags.HideInInspector;
                 v_component.hideFlags |= HideFlags.NotEditable;
             }
         }
     }
     foreach (Transform v_child in transform)
     {
         if (v_child != null)
         {
             KiltUtils.LockObject(v_child.gameObject);
         }
     }
 }
    protected virtual void CheckCanvasAndGraphicsRaycaster()
    {
        Canvas v_canvas = GetComponent <Canvas>();

        UnityEngine.UI.GraphicRaycaster v_graphicsRayCaster = GetComponent <UnityEngine.UI.GraphicRaycaster>();
        if (!FullScreenRendering)
        {
            if (v_graphicsRayCaster != null)
            {
                KiltUtils.DestroyImmediate(v_graphicsRayCaster);
            }
            if (v_canvas != null)
            {
                KiltUtils.Destroy(v_canvas);
            }
        }
        else
        {
            if (v_canvas == null)
            {
                v_canvas = gameObject.AddComponent <Canvas>();
            }
            if (v_graphicsRayCaster == null)
            {
                v_graphicsRayCaster = gameObject.AddComponent <UnityEngine.UI.GraphicRaycaster>();
            }
        }
    }
    public static GameObject InstantiateEffectOverOwner(Transform p_owner, GameObject p_effect, bool p_forceLocalScale = true, bool p_instantiateInOwnerParent = true, bool p_keepOriginalRotation = false)
    {
        GameObject v_effectObject = null;

        if (p_effect != null)
        {
            if (p_owner != null)
            {
                v_effectObject = GameObject.Instantiate(p_effect) as GameObject;
                v_effectObject.transform.position = p_owner.position;
                v_effectObject.transform.rotation = p_owner.rotation;
                v_effectObject.transform.parent   = p_instantiateInOwnerParent? p_owner.parent : p_owner;
                v_effectObject.transform.Rotate(p_effect.transform.localEulerAngles);
                //Force Scale to original one
                if (p_forceLocalScale)
                {
                    v_effectObject.transform.localScale = p_effect.transform.localScale;
                }
                else
                {
                    KiltUtils.SetLossyScale(v_effectObject.transform, p_effect.transform.localScale);
                }
                if (p_keepOriginalRotation)
                {
                    v_effectObject.transform.eulerAngles = p_effect.transform.localEulerAngles;
                }
            }
            else
            {
                v_effectObject = GameObject.Instantiate(p_effect) as GameObject;
            }
        }
        return(v_effectObject);
    }
    protected virtual Rope2D CreateRope(GameObject p_objectA, GameObject p_objectB, int p_indexA = 0, int p_indexB = 0)
    {
        TackRope v_returnedRope = null;

        if (m_windowInformation.Rope != null && p_objectA != null && p_objectB != null)
        {
            GameObject v_ropeInSceneObject = KiltUtils.Instantiate(m_windowInformation.Rope.gameObject);
            v_ropeInSceneObject.name             = m_windowInformation.Rope.name + "[(" + p_objectA.name.Replace("(Selected)", "") + ") to (" + p_objectB.name.Replace("(Selected)", "") + ")]";
            v_ropeInSceneObject.transform.parent = m_windowInformation.RopeParent;
            if (m_windowInformation.UsePrefabRopeScale)
            {
                v_ropeInSceneObject.transform.localScale = m_windowInformation.Rope.transform.localScale;
            }

            TackRope v_ropeInScene = v_ropeInSceneObject.GetComponent <TackRope>();
            v_ropeInScene.ObjectA                    = p_objectA;
            v_ropeInScene.ObjectB                    = p_objectB;
            v_ropeInScene.TackAIndex                 = p_indexA;
            v_ropeInScene.TackBIndex                 = p_indexB;
            v_ropeInScene.RopeDepth                  = m_windowInformation.RopeDepth;
            v_ropeInScene.RopeSortingLayerName       = m_windowInformation.RopeSortingLayerName;
            v_ropeInScene.AutoCalculateAmountOfNodes = m_windowInformation.AutomaticCalculateNodes;
            v_ropeInScene.AmountOfNodes              = m_windowInformation.AmountOfNodes;
            v_ropeInScene.CustomNodePrefab           = m_windowInformation.CustomPrefabNode;

            v_returnedRope = v_ropeInScene;
            EditorUtility.SetDirty(v_ropeInSceneObject);
        }
        return(v_returnedRope);
    }
示例#8
0
 protected virtual void Update()
 {
     if (Trackable == null)
     {
         KiltUtils.Destroy(this.gameObject);
     }
 }
 public void AddRandomRotation(Rigidbody2D p_body)
 {
     if (p_body != null)
     {
         float v_randomRotation = KiltUtils.RandomRange(m_minAngularVelocity, m_maxAngularVelocity);
         p_body.angularVelocity += v_randomRotation;
     }
 }
示例#10
0
 protected virtual void ResetAllRigidBodyValues()
 {
     Rigidbody2D[] v_allRigidInScene = KiltUtils.FindAllComponentsOfType <Rigidbody2D>(false);
     foreach (Rigidbody2D v_body in v_allRigidInScene)
     {
         KiltUtils.ClearRigidBody2D(v_body);
     }
 }
示例#11
0
 protected virtual void OnLevelLoaded()
 {
     if (MouseDragger.Instance != null && MouseDragger.Instance != this)
     {
         KiltUtils.Destroy(MouseDragger.Instance.gameObject);
     }
     MouseDragger.Instance = this;
 }
示例#12
0
	protected virtual void ClearChildrens()
	{
		AudioSource v_backgroundMusicSource = BackgroundMusicSource;
		foreach(Transform v_transform in transform)
		{
			if(v_transform != null && v_transform != v_backgroundMusicSource.transform)
				KiltUtils.Destroy(v_transform.gameObject);
		}
	}
示例#13
0
    private BlockSelector CopyThisComponent(GameObject p_target)
    {
        BlockSelector v_newComponent = null;

        if (p_target != null)
        {
            v_newComponent = KiltUtils.CopyComponent <BlockSelector>(p_target, this);
        }
        return(v_newComponent);
    }
示例#14
0
 protected virtual void Refresh(bool p_force = true)
 {
     if (p_force || (m_windowInformation.Ballons != null || m_windowInformation.Ropes != null))
     {
         m_windowInformation.Ballons             = new List <BalloonProperty>(KiltUtils.FindAllResourcesComponentsAtFolder <BalloonProperty>("Prefabs"));
         m_windowInformation.Ropes               = new List <TackRope>(KiltUtils.FindAllResourcesComponentsAtFolder <TackRope>("Prefabs"));
         m_windowInformation.SelectedRopeIndex   = 0;
         m_windowInformation.SelectedBallonIndex = 0;
     }
 }
 public virtual void RecalcForcesAndClearBody(bool p_forceRecalc = false, bool p_ropesMassOnly = false)
 {
     if (_needRecalcAndClear || p_forceRecalc)
     {
         RecalcForces(true, p_ropesMassOnly);
         _needRecalcAndClear = false;
         KiltUtils.ClearRigidBody2D(RigidBody2DComponent);
         ResetTimeToLerp();
     }
 }
 public override void Send()
 {
     foreach (ObjectShowActionStruct v_objectTarget in Targets)
     {
         if (v_objectTarget != null && v_objectTarget.ObjectToApply != null)
         {
             KiltUtils.SetContainerVisibility(v_objectTarget.ObjectToApply, v_objectTarget.Action, v_objectTarget.DelayToCallAction, false);
         }
     }
 }
 protected virtual void DeleteRopeClicked()
 {
     foreach (Rope2D v_rope in m_currentCreatedRopes)
     {
         if (v_rope != null)
         {
             KiltUtils.Destroy(v_rope.gameObject);
         }
     }
 }
示例#18
0
 //Use this functions to update Parameters to next scene when level was loaded
 protected void OnLevelWasLoaded(int level)
 {
     Screen.SetResolution(Screen.width, Screen.height, Screen.fullScreen);
     ApplyNextParametersInCurrentParamenters();
     if (SceneManager.OnLevelLoaded != null)
     {
         SceneManager.OnLevelLoaded(SceneManager.OldLevelName, SceneManager.CurrentLevelName);
     }
     KiltUtils.Destroy(this.gameObject);
 }
    public static string ReadAllText(string p_fullPathWithFileName)
    {
        string v_return = "";

        try
        {
            string v_fileNameWithoutExtension = KiltUtils.GetFileName(p_fullPathWithFileName, false);
            string v_resultPath    = p_fullPathWithFileName;
            string v_folderPath    = v_resultPath.Replace(KiltUtils.GetFileName(p_fullPathWithFileName, true), "");
            string v_resourcesPath = KiltUtils.PathCombine(v_folderPath, v_fileNameWithoutExtension);
            v_resourcesPath = KiltUtils.PathUncombine(v_resourcesPath, KiltUtils.GetCurrentDataPath());

            //Try Resources.Load
            if (string.IsNullOrEmpty(v_return))
            {
                TextAsset v_textAsset = Resources.Load(v_resourcesPath, typeof(TextAsset)) as TextAsset;
                if (v_textAsset != null && !string.IsNullOrEmpty(v_textAsset.text))
                {
                    v_return = v_textAsset.text;
                }
                ;
            }
            //Try Traditional Methods
                        #if UNITY_WEBPLAYER && !UNITY_EDITOR
            if (string.IsNullOrEmpty(v_return))
            {
                string v_textObject = ReadAllTextFromPlayerPrefs(v_resourcesPath);
                if (!string.IsNullOrEmpty(v_textObject))
                {
                    v_return = v_textObject;
                }
            }
                        #elif UNITY_WEBPLAYER && UNITY_EDITOR
            if (string.IsNullOrEmpty(v_return) && KiltUtils.CallEditorStaticFunctionWithReturn <bool>("SystemIOEditorWebPlayer", "FileExists", v_resultPath))
            {
                string v_textObject = KiltUtils.CallEditorStaticFunctionWithReturn <string>("SystemIOEditorWebPlayer", "ReadAllText", v_resultPath);
                if (!string.IsNullOrEmpty(v_textObject))
                {
                    v_return = v_textObject;
                }
            }
                        #elif !UNITY_WEBPLAYER
            if (string.IsNullOrEmpty(v_return) && System.IO.File.Exists(v_resultPath))
            {
                string v_textObject = File.ReadAllText(v_resultPath);
                if (!string.IsNullOrEmpty(v_textObject))
                {
                    v_return = v_textObject;
                }
            }
                        #endif
        }
        catch {}
        return(v_return);
    }
    protected virtual GameObject CreateFragment(GameObject p_parent, Sprite p_sprite, int p_index)
    {
        Vector2 v_minInitialOffset = GetGlobalMinInitialOffSet();
        Vector2 v_maxInitialOffset = GetGlobalMaxInitialOffSet();

        GameObject v_object = new GameObject("Frag");

        v_object.transform.parent     = p_parent != null? p_parent.transform : this.transform.parent;
        v_object.transform.localScale = new Vector3(m_fragmentScale * this.transform.localScale.x, m_fragmentScale * this.transform.localScale.y, m_fragmentScale * this.transform.localScale.z);
        v_object.transform.position   = new Vector3(this.transform.position.x + KiltUtils.RandomRange(v_minInitialOffset.x, v_maxInitialOffset.x), this.transform.position.y + KiltUtils.RandomRange(v_minInitialOffset.y, v_maxInitialOffset.y), this.transform.position.z);
        v_object.transform.rotation   = this.transform.rotation;
        v_object.AddComponent <Fragment>();
        Rigidbody2D v_body = v_object.AddComponent <Rigidbody2D>();

        if (m_createFragmentCollider)
        {
            CircleCollider2D v_collider = v_object.AddComponent <CircleCollider2D>();
            v_collider.radius = 0.01f;
            CircleCollider2D v_collider2 = v_object.AddComponent <CircleCollider2D>();
            v_collider2.radius = 0.01f;
            v_collider2.offset = new Vector2(0.005f, 0.005f);
        }
        if (this.GetComponent <Rigidbody2D>() != null)
        {
            v_body.mass            = Mathf.Max(0.001f, m_fragmentMass); //(rigidbody2D.mass/Mathf.Max(1,m_maxAmountOfFragments))/25;
            v_body.velocity        = UseOldRigidBodyVelocity? GetComponent <Rigidbody2D>().velocity : Vector2.zero;
            v_body.angularVelocity = UseOldRigidBodyVelocity? GetComponent <Rigidbody2D>().angularVelocity : 0;
            v_body.gravityScale    = m_fragmentGravityScale;
        }
        SpriteRenderer v_spriteRenderer = v_object.AddComponent <SpriteRenderer>();

        v_spriteRenderer.sprite = p_sprite;
        SpriteRenderer v_currentSpriteRenderer = gameObject.GetComponent <SpriteRenderer>();

        if (v_currentSpriteRenderer != null)
        {
            v_spriteRenderer.color            = v_currentSpriteRenderer.color;  //renderer.material.GetColor("_Color");
            v_spriteRenderer.material         = v_currentSpriteRenderer.material;
            v_spriteRenderer.sortingLayerID   = v_currentSpriteRenderer.sortingLayerID;
            v_spriteRenderer.sortingLayerName = v_currentSpriteRenderer.sortingLayerName;
            v_spriteRenderer.sortingOrder     = 15;
        }
        AddRandomImpulse(v_body);
        AddRandomRotation(v_body);
        if (m_enableIndividualFragmentEffect && m_individualFragmentEffect != null)
        {
            GameObject v_effect = GameObject.Instantiate(m_individualFragmentEffect) as GameObject;
            v_effect.transform.parent        = v_object.transform;
            v_effect.transform.localPosition = Vector2.zero;
            v_effect.transform.rotation      = Quaternion.identity;
            v_effect.transform.localScale    = Vector3.one;
        }
        //PauseManager.Pause();
        return(v_object);
    }
示例#21
0
    public virtual float GetSumOfOtherObjectsMass(bool p_includeChildrens = true, bool p_multiplyByGravityScale = true)
    {
        float             v_sumOfOtherObjectsMass = 0;
        List <GameObject> v_otherObjects          = GetAllOtherAttachedObjectsInPluggedRopes();

        foreach (GameObject v_object in v_otherObjects)
        {
            v_sumOfOtherObjectsMass += KiltUtils.GetObjectMass(v_object, p_includeChildrens, p_multiplyByGravityScale);
        }
        return(v_sumOfOtherObjectsMass);
    }
 public void AddRandomImpulse(Rigidbody2D p_body)
 {
     if (p_body != null)
     {
         float   v_randomImpulse = KiltUtils.RandomRange(m_minImpulseForce, m_maxImpulseForce);
         Vector2 v_finalVector   = VectorHelper.Direction(p_body.gameObject.transform.parent.position, p_body.gameObject.transform.position);
         v_finalVector = new Vector2(v_finalVector.x * v_randomImpulse, v_finalVector.y * v_randomImpulse);
         p_body.AddForce(v_finalVector, ForceMode2D.Impulse);
         //p_body.AddForce(new Vector2(0,v_randomImpulse));
     }
 }
示例#23
0
    public float GetSumOfIndirectObjectsMass(bool p_includeOtherPluggedObjects = true, bool p_includeChildrens = true, bool p_multiplyByGravityScale = true)
    {
        List <GameObject> v_indirectOtherObjectsList = GetAllIndirectObjects(p_includeOtherPluggedObjects);
        float             v_massSum = 0;

        foreach (GameObject v_object in v_indirectOtherObjectsList)
        {
            v_massSum += KiltUtils.GetObjectMass(v_object, p_includeChildrens, p_multiplyByGravityScale);
        }
        return(v_massSum);
    }
示例#24
0
 public virtual void Destroy()
 {
     //gameObject.SetActive(false);
     if (OnDestroyedByUser != null)
     {
         OnDestroyedByUser();
     }
     StartDestroyEffects(UseFragments);
     KiltUtils.Destroy(this.gameObject);
     //DestroyImmediate(this.gameObject);
 }
    public virtual bool HideParticleAuraRadius()
    {
        bool v_sucess = false;

        if (_currentRadiusAura != null)
        {
            KiltUtils.DestroyImmediate(_currentRadiusAura);
            _currentRadiusAura = null;
            v_sucess           = true;
        }
        return(v_sucess);
    }
示例#26
0
 public void CorrectSelectedPrefabIndex(bool p_force = false, bool p_canRefillFolders = true)
 {
     if (Application.isEditor || p_force)
     {
         if (CachedPrefab != null)
         {
             for (int i = 0; i < Folders.Count; i++)
             {
                 FolderPrefabs v_foldPrefab = Folders[i];
                 if (v_foldPrefab != null)
                 {
                     for (int j = 0; j < v_foldPrefab.PrefabsInFolder.Count; j++)
                     {
                         GameObject v_prefab = v_foldPrefab.PrefabsInFolder[j];
                         if (v_prefab == CachedPrefab)
                         {
                             if (m_selectedFolderIndex != i)
                             {
                                 m_selectedFolderIndex = i;
                             }
                             if (m_selectedPrefabInFolderIndex != j)
                             {
                                 m_selectedPrefabInFolderIndex = j;
                             }
                             if (p_canRefillFolders)
                             {
                                 string v_cachedPrefabPath = KiltUtils.PathCorrection(GetPrefabResourcesFilePath(CachedPrefab));
                                 string v_pathByIndex      = KiltUtils.PathCorrection("Resources/" + MainFolderPath + "/" + SelectedFolderName + "/" + SelectedPrefabName + ".prefab");
                                 if (!v_pathByIndex.Equals(v_cachedPrefabPath))
                                 {
                                     FillObjectsInFolderList(true);
                                     CorrectSelectedPrefabIndex(true, false);                                         //After refill, call it again forcing find corret index but preventing to fill again
                                 }
                             }
                             return;
                         }
                     }
                 }
             }
         }
         else
         {
             if (m_selectedFolderIndex != -1)
             {
                 m_selectedFolderIndex = -1;
             }
             if (m_selectedPrefabInFolderIndex != -1)
             {
                 m_selectedPrefabInFolderIndex = -1;
             }
         }
     }
 }
 public static void UnregisterFragment(Fragment p_frag, bool p_forceDestroy = false)
 {
     if (p_frag != null)
     {
         m_currentAmountOfFragmentsInScene--;
         m_currentAmountOfFragmentsInScene = Mathf.Max(0, m_currentAmountOfFragmentsInScene);
         if (p_forceDestroy)
         {
             KiltUtils.DestroyImmediate(p_frag.gameObject);
         }
     }
 }
 protected virtual void Refresh(bool p_force = true)
 {
     if (p_force || m_windowInformation.Ropes != null)
     {
         GameObject v_parentTransform = GameObject.Find("RopesContainer");
         if (v_parentTransform != null)
         {
             m_windowInformation.RopeParent = v_parentTransform.transform;
         }
         m_windowInformation.Ropes             = new List <Rope2D>(KiltUtils.FindAllResourcesComponentsAtFolder <Rope2D>("Prefabs"));
         m_windowInformation.SelectedRopeIndex = 0;
     }
 }
 //If Any Parent or Self contain Focus, Or Focus equal null and panel is Opened or GameObject is Active
 public static bool IsUnderFocus(GameObject p_object)
 {
     if (p_object != null)
     {
         FocusContainer v_focus      = FocusContainer.GetFocus();
         PanelStateEnum v_panelState = v_focus == null? PanelStateEnum.Opened : KiltUtils.GetContainerVisibility(v_focus.gameObject);
         if (v_panelState == PanelStateEnum.Opened && (FocusContainer.GetDirectFocusContainerComponent(p_object) == v_focus))
         {
             return(true);
         }
     }
     return(false);
 }
示例#30
0
    public bool Cut()
    {
        if (RopeParent != null)
        {
            return(RopeParent.CutNode(this.gameObject));
        }
        else
        {
            KiltUtils.DestroyImmediate(this.gameObject);
        }

        return(true);
    }